Example usage for com.mongodb MapReduceOutput getCollectionName

List of usage examples for com.mongodb MapReduceOutput getCollectionName

Introduction

In this page you can find the example usage for com.mongodb MapReduceOutput getCollectionName.

Prototype

@Nullable
public final String getCollectionName() 

Source Link

Document

Get the name of the collection that the results of the map reduce were saved into.

Usage

From source file:fr.gouv.vitam.mdbes.MainMapReduce.java

License:Open Source License

protected static void oneShot(MongoDbAccess dbvitam) throws InvalidParseOperationException,
        InvalidExecOperationException, InstantiationException, IllegalAccessException {
    // Requesting
    if (map == null) {
        map = "function() {" + "flattened = serializeDocFiltered(this, MAXDEPTH, FILTER);"
                + "for (var key in flattened) {" + "var value = flattened[key];"
                + "var valueType = varietyTypeOf(value);"
                + "var finalvalue = { types : [ valueType ], occurences : 1};"
                //                + "var finalvalue = { occurences : 1};"
                + "emit(key, finalvalue); } }";
    }//from w  w w  .ja va 2  s .  com
    if (reduce == null) {
        reduce = "function(key,values) {" + "var typeset = new Set();" + "var occur = 0;"
                + "for (var idx = 0; idx < values.length; idx++) {" + "occur += values[idx].occurences;"
                + "typeset.add(values[idx].types);"
                + "} return { types : typeset.asArray(), occurences : occur }; }";
        //                + "} return { occurences : occur }; }";

    }
    if (output == null) {
        output = "AttributeUsage";
    }
    MapReduceCommand mapReduceCommand = new MapReduceCommand(dbvitam.daips.collection, map, reduce, output,
            OutputType.REDUCE, new BasicDBObject());
    if (options != null) {
        String[] optionsArray = options.split(",");
        Map<String, Object> mapScope = new HashMap<String, Object>();
        for (String string : optionsArray) {
            String[] kv = string.split("=");
            mapScope.put(kv[0], getParsedString(kv[1]));
        }
        mapReduceCommand.setScope(mapScope);
    } else {
        Map<String, Object> mapScope = new HashMap<String, Object>();
        mapScope.put("MAXDEPTH", 5);
        mapScope.put("FILTER", "_dds");
        mapReduceCommand.setScope(mapScope);
    }
    mapReduceCommand.addExtraOption("nonAtomic", true);
    mapReduceCommand.addExtraOption("jsMode", true);
    MapReduceOutput output = dbvitam.daips.collection.mapReduce(mapReduceCommand);
    System.out.println("Duration: " + output.getDuration() + " Saved into: " + output.getCollectionName()
            + " Input: " + output.getInputCount() + " Emit: " + output.getEmitCount() + " Output: "
            + output.getOutputCount() + "\nCmd: " + output.getCommand());
    Iterable<DBObject> iterable = output.results();
    for (DBObject dbObject : iterable) {
        System.out.println(dbObject.toString());
    }
}

From source file:org.springframework.data.mongodb.core.mapreduce.MapReduceResults.java

License:Apache License

private static String parseOutputCollection(final MapReduceOutput mapReduceOutput) {
    return mapReduceOutput.getCollectionName();
}