[英]Mongo/Java Map-Reduce function - MongoCommandException
I get the following error: com.mongodb.MongoCommandException: Command failed with error 139: 'SyntaxError: missing ;我收到以下错误: com.mongodb.MongoCommandException: 命令失败,错误 139: 'SyntaxError: missing ; before statement @:1:60 ' on server localhost:27017.
before 语句 @:1:60 ' 在服务器 localhost:27017 上。 The full response is { "ok" : 0.0, "errmsg" : "SyntaxError: missing ; before statement @:1:60\\n", "code" : 139
完整的响应是 { "ok" : 0.0, "errmsg" : "SyntaxError: missing ; before statement @:1:60\\n", "code" : 139
It seems I am missing a ;看来我错过了一个; but cannot seem to see where.
但似乎看不到哪里。 The method is self-explanatory, I tend to create an map/reduce via mongo.
该方法是不言自明的,我倾向于通过 mongo 创建一个 map/reduce。 Any help is appreciated.
任何帮助表示赞赏。
public void mapFunction()
{
Mongo mongo = null;
try{
mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("amarokforumdb");
DBCollection comments = db.getCollection("comments");
String map = "function() { "+
"var category; " +
"var numOfDocuments = "+db+".comments.count();" +
"for(i = 0; i < numOfDocuments; i++){ " +
"if (numOfDocuments <= 100) {"+
"category = 'New Comments'; }" +
"else if(numOfDocuments > 100){" +
"category = 'Old Comments'; }}"+
"emit(category,1);};";
String reduce = "function(key, values) { " +
"var sum = 0; " +
"values.forEach(function(doc) { " +
"sum += 1; "+
"}); " +
"return {comments: sum};} ";
MapReduceCommand cmd = new MapReduceCommand(comments, map, reduce,
null, MapReduceCommand.OutputType.INLINE, null);
MapReduceOutput out = comments.mapReduce(cmd);
for (DBObject o : out.results()) {
System.out.println(o.toString());
}}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Replace the "+db+".comments.count();
替换
"+db+".comments.count();
with an integer for testing, I think you got something wrong with that +db+
part使用整数进行测试,我认为您在
+db+
部分有问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.