Example usage for com.mongodb MapReduceOutput getCommand

List of usage examples for com.mongodb MapReduceOutput getCommand

Introduction

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

Prototype

public DBObject getCommand() 

Source Link

Document

Get the original command that was sent to the database.

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); } }";
    }/*www .j a v a2s .  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());
    }
}