{"record":{"id":"87128b6ca2a96623","repo":"apache/beam","slug":"error-executing-find-command-w","errorCode":null,"errorMessage":"error executing find command: %w","messagePattern":"error executing find command: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/read.go","lineNumber":303,"sourceCode":"\t}\n\n\tresult := cursorResult{isExhausted: true}\n\trt.TryClaim(result)\n\n\treturn cursor.Err()\n}\n\nfunc (fn *readFn) getCursor(\n\tctx context.Context,\n\tfilter bson.M,\n) (*mongo.Cursor, error) {\n\topts := options.Find().\n\t\tSetProjection(fn.projection).\n\t\tSetSort(bson.M{\"_id\": 1})\n\n\tcursor, err := fn.collection.Find(ctx, filter, opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing find command: %w\", err)\n\t}\n\n\treturn cursor, nil\n}\n\nfunc decodeDocument(cursor *mongo.Cursor, t reflect.Type) (id any, value any, err error) {\n\tvar docID documentID\n\tif err := cursor.Decode(&docID); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error decoding document ID: %w\", err)\n\t}\n\n\tout := reflect.New(t).Interface()\n\tif err := cursor.Decode(out); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error decoding document: %w\", err)\n\t}\n\n\tvalue = reflect.ValueOf(out).Elem().Interface()\n","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/read.go#L285-L321","documentation":"getCursor runs collection.Find with an _id sort and optional projection to start the read cursor over the restricted range. If the find command fails, the error is wrapped as 'error executing find command' and aborts ProcessElement for that element. It means the query could not be executed or its first batch retrieved by the driver.","triggerScenarios":"ProcessElement calls getCursor; fn.collection.Find(ctx, filter, opts) fails — network/server error, unauthorized user, invalid filter (bad BSON, type mismatch on _id bounds), invalid projection, or context canceled.","commonSituations":"MongoDB unreachable or in failover when the pipeline starts reading; user missing find privilege; user-supplied filter/projection options that the server rejects; query timeout from server-side maxTimeMS or context deadline.","solutions":["Inspect the wrapped cause for the specific server error (authorization, bad query, timeout)","Verify network connectivity and server health before launching the pipeline","Check the user has find on the namespace and the filter/projection options are valid","Increase context timeout or driver socket timeouts for large collections","If transient (network), retry the pipeline — the driver's retryable reads may already cover some cases"],"exampleFix":"// before — filter with wrong type for _id range\nfilter := bson.M{\"_id\": bson.M{\"$gte\": \"abc\"}} // stored as ObjectId\n// after\noid, _ := primitive.ObjectIDFromHex(\"652f1a...\")\nfilter := bson.M{\"_id\": bson.M{\"$gte\": oid}}","handlingStrategy":"try-catch","validationCode":"// validate filter and projection before reading\nif err := coll.FindOne(ctx, filter, opts).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) {\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"cursor, err := getCursor(ctx, fn, filter)\nif err != nil {\n\treturn fmt.Errorf(\"read failed for range %v: %w\", r, err)\n}","preventionTips":["Ping the cluster at Setup; fail fast before DoFns run","Match filter _id types to stored types (ObjectId vs string)","Grant find privilege to the pipeline user","Set sane socket/context timeouts for large collections"],"tags":["mongodb","go","find","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"}