sha*_*ath 1 mongodb mongodb-java mongodb-query
我在我的代码中调用MongoDB聚合函数:
AggregationOutput output = collection.aggregate( matchUserID, unwindF, matchFUsers,projection);
Run Code Online (Sandbox Code Playgroud)
我在我的localhost中测试了我的代码,它完美无缺.当我在另一个DB(版本2.2.1)中使用相同的时,它会出现此错误:
com.mongodb.CommandResult$CommandFailure: command failed [aggregate]: { "serverUsed" : "<server address>" , "errmsg" : "no such cmd: aggregate" , "bad cmd" : { "aggregate" : .... }
Run Code Online (Sandbox Code Playgroud)
有什么线索的原因?
根据我看到的类似问题的其他答案,似乎很可能服务器实际上不是2.2.1.
你是如何检查服务器的版本号的?
从shell中试试这个:
use admin
db.runCommand( {buildInfo: 1} )
Run Code Online (Sandbox Code Playgroud)