我對MongoDB和MapReduce相當陌生。我需要在數據庫的某個集合上執行一些MapReduce。 MAP
和REDUCE_MAX
函數起作用,因爲我能夠在Mongo交互式shell(v.1.8.2)中完成我的需求。但是,我得到一個錯誤嘗試使用蒙戈Java驅動程序來執行同樣的事情MapReduce使用MongoDB Java驅動失敗,BSONElement斷言錯誤類型
我MAP
和REDUCE_MAX
功能看起來像這樣(V 2.6.3):
String MAP =
"function(){" +
"if(this.type != \"checkin\"){return;}" +
"if(!this.venue && !this.venue.id){return;}" +
"emit({userId:this.userId, venueId:this.venue.id}, {count:1});" +
"};";
String REDUCE_MAX =
"function(key, values){" +
"var res = {count:0};" +
"values.forEach(function(value){result.count += value.count;});" +
"return res;" +
"};";
這是我的命令中號執行:
MapReduceOutput sum = collection
.mapReduce(MAP, REDUCE_MAX, null, null);
這是我的錯誤:
com.mongodb.CommandResult$CommandFailure: command failed [command failed [mapreduce] { "assertion" : "wrong type for BSONElement (replace) 10 != 2" , "assertionCode" : 13111 , "errmsg" : "db assertion failure" , "ok" : 0.0}
我不知道哪個BSONElement類型錯誤。我已經使用了assertionCode: 13111
。我也檢查了MongoDB日誌,但沒有找到任何線索。
有沒有人有一個想法,我可能會錯過/做錯了什麼?如果你們需要更多的細節,請讓我知道。