MongoDB Java driver : no such cmd: aggregate

2019-07-25 11:27发布

问题:

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 ?

回答1:

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} )


回答2:

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 :)



回答3:

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/