3

I am using mongodb and querying a db using bucket stage with aggregation.
mongodb version :

db.serverBuildInfo()
{ 
    "version" : "3.6.0", 
    "versionArray" : [
        3.0, 
        6.0, 
        0.0, 
        0.0
    ], 
    "bits" : 64.0, 
    "maxBsonObjectSize" : 16777216.0, 
    "ok" : 1.0
}

My query is :

db.data.aggregate(
[    
    {
        "$bucket": 
        {
            groupBy: "$h_id",
            boundaries: [ 0, 100, 200, 300],
            default: "Other",
            output: {
                "count": { $sum: 1 },
            }
        }
    },
]);

I am getting error:

Unable to execute the selected commands

Mongo Server error (MongoCommandException): Command failed with error 304: 'Aggregation stage not supported: '$bucket'' on server mongodb-test:27017.

The full response is: { "ok" : 0.0, "errmsg" : "Aggregation stage not supported: '$bucket'", "code" : NumberInt(304) }

In document I can see that bucket is included in mongodb from version 3.4. https://docs.mongodb.com/v3.6/reference/operator/aggregation/bucket/

Can any body point out what is the reason of this error...

Stennie
  • 63,885
  • 14
  • 149
  • 175
DEV
  • 2,106
  • 3
  • 25
  • 40
  • Are you able to use other aggregation stages like `$group`, etc. – prasad_ Nov 28 '19 at 08:18
  • @prasad_: Yes, I am able to use match, group, sort, unwind ... – DEV Nov 28 '19 at 08:20
  • 1
    This isn't a MongoDB server error code or message. It looks like you are using an emulated API (likely DocumentDB) which currently does not support the `$bucket` operator. – Stennie Nov 28 '19 at 08:49
  • @Stennie: mongodb shell is also giving same error : rs0:PRIMARY> db.data.aggregate( ... [ ... { ... "$bucket": ... { ... groupBy: "$h_id", ... boundaries: [ 0, 100, 200, 300], ... default: "Other", ... output: { ... "count": { $sum: 1 }, ... } ... } ... }, ... ]); assert: command failed: { "ok" : 0, "errmsg" : "Aggregation stage not supported: '$bucket'", "code" : 304 } : aggregate failed – DEV Nov 28 '19 at 08:53
  • 4
    The error message is coming from the server you are connecting to, but since that isn't a MongoDB server message I'm guessing you are using an emulated service (which will differ in feature support). Based on the error message and incomplete `db.serverBuildInfo()` this looks like AWS DocumentDB, which does not currently have support for `$bucket` and many other aggregation operators and stages: https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html#mongo-apis-aggregation-pipeline-stage. – Stennie Nov 28 '19 at 09:06
  • @Stennie: OK understood, this is why getting error message. thank you. – DEV Nov 28 '19 at 09:48

0 Answers0