简体   繁体   中英

Acessing inner element of json array from mapreduce

My sample Json object is as follows

{
    "numRecommenders": 0,
    "publicProfileUrl": "http://www.linkedin.com/pub/heena-vyas/16/786/826",
    "positions": {
        "total": 1,
        "positionList": [
            {
                "id": "91286566",
                "title": "senior executive",
                "company": {
                    "name": "Reliance",
                    "industry": "Oil & Energy",
                    "type": "Public Company",
                    "size": "10,001+ employees"
                },
                "isCurrent": true
            }
        ]
    },

My mapreduce function is give below:

String map = "function() {"
                 +"for (index in this.positions.positionList) {"
                        +"emit(this.positions.positionList[index].company.name, {count: 1});"
                   +"}}";

        String reduce = "function(key, values) {" + "var sum = 0;"
                + "values.forEach(function(value) {" + "sum += value['count'];"
                + "});" + "return {count: sum};" + "};";

        MapReduceCommand mapReduceCommand = new MapReduceCommand(
                mongoCollection, map, reduce.toString(), null,
                MapReduceCommand.OutputType.INLINE, null);

        MapReduceOutput out = mongoCollection.mapReduce(mapReduceCommand);

But current I'm working with 1.5 million objects from mongoDb.

I'm getting the following exception..

Exception in thread "main" com.mongodb.CommandResult$CommandFailure: command failed [command failed [mapreduce] { "assertion" : "too much data for in memory map/reduce" , "assertionCode" : 13604 , "errmsg" : "db assertion failure" , "ok" : 0.0} at com.mongodb.CommandResult.getException(CommandResult.java:70) at com.mongodb.CommandResult.throwOnError(CommandResult.java:116) at com.mongodb.DBCollection.mapReduce(DBCollection.java:961) at com.mongo.dboperations.MongoStorage.runGroupCommand(MongoStorage.java:126)

at com.mongo.dboperations.MongoStorage.main(MongoStorage.java:218)

How to resolve this exception?

Inline output for map/reduce in MongoDB is the fastest option, provided that your output fits within the 16 MB limit. Beyond that, you have to output to a collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM