{"record":{"id":"a8af093154077299","repo":"apache/beam","slug":"err-id-range-restriction","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/id_range_restriction.go","lineNumber":57,"sourceCode":"type idRangeRestriction struct {\n\tIDRange      idRange\n\tCustomFilter bson.M\n\tCount        int64\n}\n\n// newIDRangeRestriction creates a new idRangeRestriction and counts the documents within the ID\n// range that match the custom filter.\nfunc newIDRangeRestriction(\n\tctx context.Context,\n\tcollection *mongo.Collection,\n\tidRange idRange,\n\tfilter bson.M,\n) idRangeRestriction {\n\tmergedFilter := mergeFilters(idRange.Filter(), filter)\n\n\tcount, err := collection.CountDocuments(ctx, mergedFilter)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn idRangeRestriction{\n\t\tIDRange:      idRange,\n\t\tCustomFilter: filter,\n\t\tCount:        count,\n\t}\n}\n\n// Filter returns a bson.M filter based on the restriction's ID range and custom filter.\nfunc (r idRangeRestriction) Filter() bson.M {\n\tidFilter := r.IDRange.Filter()\n\treturn mergeFilters(idFilter, r.CustomFilter)\n}\n\n// mergeFilters merges the ID filter and the custom filter into a single bson.M filter.\nfunc mergeFilters(idFilter bson.M, customFilter bson.M) bson.M {\n\tif len(idFilter) == 0 {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/id_range_restriction.go#L39-L75","documentation":"mongodbio's newIDRangeRestriction panics when CountDocuments fails while merging the ID-range filter with the user filter to size a restriction. The document count is required for the restriction's splitting logic, so the error cannot be returned through the normal pipeline path and is raised as a panic. It usually reflects a connectivity, authentication, or bad-filter problem against MongoDB.","triggerScenarios":"Calling CreateInitialRestriction (or building restrictions from ID ranges) when the MongoDB collection is unreachable, credentials are wrong, the server times out, or the merged BSON filter contains invalid operators like $foo that the server rejects.","commonSituations":"MongoDB behind VPC not reachable from the worker; wrong URI/password; version mismatch where a filter operator is unsupported; collection dropped mid-pipeline setup.","solutions":["Verify the MongoDB URI, credentials, and network reachability from where the code runs","Validate the bson.M filter operators against your server's MongoDB version","Check mongod logs and collection existence","Wrap the call and recover() in pipeline construction code to convert the panic into a logged error"],"exampleFix":"// before\nres := mongodbio.CreateInitialRestriction(...) // panics on count error\n// after\nfunc() {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"mongodbio restriction failed: %v\", r)\n        }\n    }()\n    res := mongodbio.CreateInitialRestriction(...)\n    _ = res\n}()","handlingStrategy":"try-catch","validationCode":"if err := client.Ping(ctx, nil); err != nil { return fmt.Errorf(\"mongo unreachable: %w\", err) }\n// validate filter operators against server version before building restrictions","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Fatalf(\"mongodbio restriction: %v\", r) } }()","preventionTips":["Ping MongoDB during pipeline setup before creating restrictions","Keep filter documents simple and version-compatible","Monitor mongod logs for auth/timeout errors correlated with pipeline starts"],"tags":["go","mongodb","panic","database"],"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"}