when I run this aggregation pipeline in Robomongo
db.getCollection('xyz').aggregate([{$match: {tyu: "asd", ghj: "qwe"}},
{$sample: {size: 5}}])
I receive this error:
assert: command failed: {
"errmsg" : "exception: Unrecognized pipeline stage name: '$sample'",
"code" : 16436,
"ok" : 0
I'm using mongodb ver 3.2.6 and since $sample is supported from 3.2 onward.
(https://docs.mongodb.com/manual/reference/operator/aggregation/sample/#pipe._S_sample)
Im a little confused as to why I receive this error message.
Maybe I'm just missing something small.
Thanks
As stated in the comments of the question. Mongo client had a version of 3.2.6 but Mongo db had a version of 3.0.6.
I used version() in the shell to get the client's version and
db.version() to get the DB's version.
ver 3.0.6 is too low to support $sample as stated in the mongo documentation
https://docs.mongodb.com/manual/reference/operator/aggregation/sample/#pipe._S_sample
Related
Is there a way we can set internalQueryMaxAddToSetBytes in mongdb version 3.6.9 ? The admin command db.adminCommand({setParameter: 1, internalQueryMaxAddToSetBytes: newLimit}) is not supported in 3.6.9.
I got below error message
"errmsg" : "attempted to set unrecognized parameter [internalQueryMaxAddToSetBytes], use help:true to see options "
How can we configure this for 3.6.9?
Related - https://jira.mongodb.org/browse/SERVER-44869
https://jira.mongodb.org/browse/SERVER-44174
Per the server ticket this feature requires 3.6.17 or newer server.
Mongo aggregation framework has some changes in version 3.6 Earlier aggregation queries with monger are not working even when we pass :cursor {} as an option. Is there any workaround or do we have to wait for the next monger release?. The error we get is specified below
MongoCommandException Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" } com.mongodb.connection.ProtocolHelper.getCommandFailureException (ProtocolHelper.java:115)
by OSt advice, I could run monger aggregation sample with codes below.
(mc/aggregate db coll
[{"$project" {:subtotal {"$multiply" ["$quantity", "$price"]}
:_id "$state"}}]
:cursor {:batch-size 0})
thanks!
According to mongo db spec, cursor became a required field in some cases. So you should provide it through monger API. It is not a problem in monger, it is a breakable change in mongo db API.
{ "ok" : 0,
"errmsg" : "The featureCompatibilityVersion must be 3.6 to create a collection validator using 3.6 query features. See http://dochub.mongodb.org/core/3.6-feature-compatibility.",
"code" : 224,
"codeName" : "QueryFeatureNotAllowed"
}
The Above is the error in MongoDB.
Version - 3.6.2;
OS: Ubuntu 16.0.4;
Thank you guys for trying to answer my question but I solved the issue myself.
For me the solution was to execute the following command:
db.adminCommand({setFeatureCompatibilityVersion: "3.6"})
I have the following mongo versions
db version v2.4.1
MongoDB shell version: 2.4.1,
and
db version v2.2.1-rc1, pdfile version 4.5,
MongoDB shell version: 2.2.1-rc1
installed on 64-bit windows 7 machine.
I have a collection having 10001000 (10 million+) records, when I use V 2.4.1 to aggregate, it fails with the following
error:
Fatal error in CALL_AND_RETRY_2
Allocation failed - process out of memory
However when I use V 2.2.1-rc1, to aggregate the same collection, it works fine and gives result in around 1 minute.
Sample document of the collection that is being aggregated:
{
"_id" : ObjectId("516bdd1c39b10c722792e007"),
"f1" : 10000010,
"f2" : 10000000,
"key" : 0
}
Aggregation Command:
{$group: {"_id": "$key", total: {$sum: "$f1"}}}
Command used to populate records:
for(var i = 10011000; i < 10041000; ++i)
{
db.testp.insert({"f1": i+10, "f2": i, "key": i%1000})
}
How much memory do you have? Could it be the $group is taking up more than 10% of available memory and causing the error? See the aggregation documentation on memory for cumulative operators.
edit 1:
Out of interest - does the aggregation work outside the shell? eg calling it from a driver.
I have seen similar v8 errors and as the shell was updated to v8 in 2.4 Theres a chance it could be that.
edit 2:
If the resulting array is too big in the shell then that can also trigger the error: see SERVER-8859. To work around you might need to run multiple aggregations, either by doing a $match early on to limit the working set or even a $skip and $limit to paginate through the result set.
I tried your aggregation with 10,070,999 docs on 2.4.1 on a mac and didn't get the error
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 ?
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} )
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 :)
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/