来自mapreduce的json数组的内部元素



我的示例 Json 对象如下所示

{
    "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
            }
        ]
    },

我的mapreduce函数给出如下:

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);

但目前我正在使用来自 mongoDB 的 150 万个对象。

我收到以下异常..

线程 "main" 中的异常 com.mongodb.CommandResult$CommandFailure: 命令失败 [命令失败 [mapreduce] { "assertion" : "内存映射/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)

如何解决此异常?

MongoDB中map/reduce的内联输出是最快的选择,前提是您的输出符合16 MB的限制。 除此之外,您必须输出到集合。

相关内容

  • 没有找到相关文章

最新更新