{"record":{"id":"d86b65ed18eca8c8","repo":"apache/beam","slug":"error-executing-bucketauto-aggregation-w","errorCode":null,"errorMessage":"error executing bucketAuto aggregation: %w","messagePattern":"error executing bucketAuto aggregation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/id_range_split.go","lineNumber":120,"sourceCode":"\tpipeline := mongo.Pipeline{\n\t\tbson.D{{\n\t\t\tKey:   \"$match\",\n\t\t\tValue: filter,\n\t\t}},\n\t\tbson.D{{\n\t\t\tKey: \"$bucketAuto\",\n\t\t\tValue: bson.M{\n\t\t\t\t\"groupBy\": \"$_id\",\n\t\t\t\t\"buckets\": count,\n\t\t\t},\n\t\t}},\n\t}\n\n\topts := options.Aggregate().SetAllowDiskUse(true)\n\n\tcursor, err := collection.Aggregate(ctx, pipeline, opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing bucketAuto aggregation: %w\", err)\n\t}\n\n\tvar buckets []bucket\n\tif err := cursor.All(ctx, &buckets); err != nil {\n\t\treturn nil, fmt.Errorf(\"error decoding buckets: %w\", err)\n\t}\n\n\treturn buckets, nil\n}\n\nfunc idRangesFromBuckets(buckets []bucket, outerRange idRange) []idRange {\n\tif len(buckets) == 0 {\n\t\treturn nil\n\t}\n\n\tranges := make([]idRange, len(buckets))\n\n\tfor i := 0; i < len(buckets); i++ {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/id_range_split.go#L102-L138","documentation":"getBuckets executes a $bucketAuto aggregation pipeline to partition the collection's _id range into roughly equal-size buckets for splitting. If collection.Aggregate fails to start, the error is wrapped as 'error executing bucketAuto aggregation'. This indicates the aggregation itself was rejected or failed server/network-side.","triggerScenarios":"bucketAutoSplits calls getBuckets; the $bucketAuto pipeline (with AllowDiskUse) is rejected by the server — invalid syntax for the server version, authorization failure, memory limits even with disk use, or network/context failure.","commonSituations":"Older MongoDB servers (<3.4) that lack $bucketAuto; user without aggregate permission on the collection; very large collections exceeding execution limits; context canceled mid-aggregation during split planning.","solutions":["Verify the MongoDB server version supports $bucketAuto (3.4+)","Grant the connecting user the aggregate privilege on the collection","Inspect the wrapped cause for a specific server error (e.g. code 168 for invalid pipeline)","Increase allowDiskUse capacity / reduce parallelism, or switch to the splitVector-based split strategy","Check network stability and context deadlines during planning"],"exampleFix":"// before — server 3.2 lacks $bucketAuto, falls over\nsplits, err := bucketAutoSplits(ctx, collection, r, numSplits, bundleSize)\n// after — use splitVector strategy\ncfg := Config{SplitStrategy: SplitVectorStrategy}\nsplits, err := splitVectorSplits(ctx, db, collection.Name(), r, numSplits, bundleSize)","handlingStrategy":"retry","validationCode":"// $bucketAuto needs MongoDB >= 3.4\nvar v struct{ Version string }\ndb.RunCommand(ctx, bson.D{{Key:\"buildInfo\", Value:1}}).Decode(&v)\nmajor := strings.Split(strings.TrimPrefix(v.Version,\"v\"), \".\")\n// require major>3 || (major==3 && minor>=4)","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n\tbuckets, err := getBuckets(ctx, coll, pipeline)\n\tif err == nil { break }\n\ttime.Sleep(backoff(attempt))\n}","preventionTips":["Use MongoDB >= 3.4 for $bucketAuto","Grant aggregate privilege on the collection","Prefer splitVector on sharded/managed clusters","Set allowDiskUse and generous context timeouts"],"tags":["mongodb","go","aggregation","split"],"backgroundTag":"database-query-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}