MongoDB Java driver : no such cmd: aggregate

2019-07-25 10:43发布

I am calling the MongoDB aggregate function in my code as :

AggregationOutput output = collection.aggregate( matchUserID, unwindF, matchFUsers,projection);

I have tested my code in my localhost, and it works perfect. When I am using the same in another DB (version 2.2.1), it gives this error :

com.mongodb.CommandResult$CommandFailure: command failed [aggregate]: { "serverUsed" : "<server address>" , "errmsg" : "no such cmd: aggregate" , "bad cmd" : { "aggregate" : .... }

Any clue why ?

3条回答
做个烂人
2楼-- · 2019-07-25 11:16

Based on other answers I've seen to similar questions, it seems most likely that the server is not actually 2.2.1 as you believe.

How are you checking the server's version number?

From the shell, try this:

use admin
db.runCommand( {buildInfo: 1} )
查看更多
祖国的老花朵
3楼-- · 2019-07-25 11:29

I had the same error "no such cmd: aggregate", and I tried new version of mongodb 2.4,2.6 from default debian repositories and always receiving this error.

After that installed mongodb-org-server from mongo repo and it worked http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/

查看更多
我想做一个坏孩纸
4楼-- · 2019-07-25 11:38

figured out the error. I was using the 2.9 version on the MongoDB Java driver. When I upgraded it to 2.10, it worked perfectly. Thanks folks :)

查看更多
登录 后发表回答