{"record":{"id":"88afa3ac46e43868","repo":"apache/beam","slug":"error-finding-document-id-to-split-on-w","errorCode":null,"errorMessage":"error finding document ID to split on: %w","messagePattern":"error finding document ID to split on: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/id_range_restriction.go","lineNumber":127,"sourceCode":"\treturn restrictionsFromIDRanges(ctx, collection, idRanges, r.CustomFilter), err\n}\n\n// FractionSplits divides the restriction into a lower and higher ID sub-restriction based on the\n// desired fraction of work the lower piece should be responsible for.\nfunc (r idRangeRestriction) FractionSplits(\n\tctx context.Context,\n\tcollection *mongo.Collection,\n\tfraction float64,\n) (lower, higher idRangeRestriction, err error) {\n\tskip := int64(math.Round(float64(r.Count) * fraction))\n\n\tsplitID, err := findID(ctx, collection, r.Filter(), 1, skip)\n\tif err != nil {\n\t\tif errors.Is(err, mongo.ErrNoDocuments) {\n\t\t\treturn idRangeRestriction{}, idRangeRestriction{}, nil\n\t\t}\n\n\t\treturn idRangeRestriction{}, idRangeRestriction{}, fmt.Errorf(\n\t\t\t\"error finding document ID to split on: %w\",\n\t\t\terr,\n\t\t)\n\t}\n\n\tlower = idRangeRestriction{\n\t\tIDRange: idRange{\n\t\t\tMin:          r.IDRange.Min,\n\t\t\tMinInclusive: r.IDRange.MinInclusive,\n\t\t\tMax:          splitID,\n\t\t\tMaxInclusive: false,\n\t\t},\n\t\tCustomFilter: r.CustomFilter,\n\t\tCount:        skip,\n\t}\n\n\thigher = idRangeRestriction{\n\t\tIDRange: idRange{","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/id_range_restriction.go#L109-L145","documentation":"FractionSplits uses findID to locate a document ID near the midpoint of the restriction so the id-range can be split for dynamic work rebalancing. If that find command fails for any reason other than mongo.ErrNoDocuments, the error is wrapped as 'error finding document ID to split on'. It means the split probe query against the collection failed, not that the range is unsplittable.","triggerScenarios":"Beam calls FractionSplits to split a mongodbio read restriction; the internal find command (sort by _id, skip near the middle, limit 1) fails due to network error, server error, query failure, or a bad filter document.","commonSituations":"MongoDB server restarted or connection dropped while the pipeline runs; a user-supplied filter that the server rejects (invalid BSON operator, type mismatch on _id); sharded cluster returning a transient error during a rebalance request.","solutions":["Read the wrapped cause; if it is a query error, verify the restriction's filter document is valid for the collection","Check MongoDB server health and network stability; transient errors usually resolve on the next split attempt","Validate that the filter's field types match the stored documents (e.g. string vs ObjectId for _id)","Confirm the user has find permission on the collection","Retry the pipeline; FractionSplits failures during rebalancing are often transient"],"exampleFix":"// before — filter built with wrong id type\nfilter := bson.M{\"_id\": 12345}\n// after — match stored ObjectId type\nid, _ := primitive.ObjectIDFromHex(\"652f1a...\")\nfilter := bson.M{\"_id\": id}","handlingStrategy":"try-catch","validationCode":"// validate the filter round-trips as BSON and matches at least one doc\nif err := collection.FindOne(ctx, r.Filter()).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) {\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"if _, err := split(ctx, r); err != nil {\n\tif !errors.Is(err, context.Canceled) {\n\t\tlog.Printf(\"fraction split failed, continuing unsplit: %v\", err)\n\t}\n}","preventionTips":["Keep restriction filters simple and typed to the stored _id type","Ensure the read user has find privilege","Treat split failures as non-fatal (Beam retries rebalancing)","Test filters against production-shaped data"],"tags":["mongodb","go","split","query"],"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"}