我的示例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] {“断言”:“内存映射/减少的数据太多”,“assertionCode”:13604,“errmsg “:”db断言失败“,”ok“:0.0} at com.mongodb.CommandResult.getException(CommandResult.java:70) 在com.mongodb.CommandResult.throwOnError(CommandResult.java:116) 在com.mongodb.DBCollection.mapReduce(DBCollection.java:961) 在com.mongo.dboperations.MongoStorage.runGroupCommand(MongoStorage.java:126)
如何解决此异常?
答案 0 :(得分:1)
MongoDB中map / reduce的内联输出是最快的选项,前提是输出符合16 MB的限制。除此之外,您必须输出到集合。