apache/beam · error
error executing find command: %w
Error message
error executing find command: %w
What it means
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.
Source
Thrown at sdks/go/pkg/beam/io/mongodbio/read.go:303
}
result := cursorResult{isExhausted: true}
rt.TryClaim(result)
return cursor.Err()
}
func (fn *readFn) getCursor(
ctx context.Context,
filter bson.M,
) (*mongo.Cursor, error) {
opts := options.Find().
SetProjection(fn.projection).
SetSort(bson.M{"_id": 1})
cursor, err := fn.collection.Find(ctx, filter, opts)
if err != nil {
return nil, fmt.Errorf("error executing find command: %w", err)
}
return cursor, nil
}
func decodeDocument(cursor *mongo.Cursor, t reflect.Type) (id any, value any, err error) {
var docID documentID
if err := cursor.Decode(&docID); err != nil {
return nil, nil, fmt.Errorf("error decoding document ID: %w", err)
}
out := reflect.New(t).Interface()
if err := cursor.Decode(out); err != nil {
return nil, nil, fmt.Errorf("error decoding document: %w", err)
}
value = reflect.ValueOf(out).Elem().Interface()
View on GitHub (pinned to 12126d8942)
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
Example fix
// before — filter with wrong type for _id range
filter := bson.M{"_id": bson.M{"$gte": "abc"}} // stored as ObjectId
// after
oid, _ := primitive.ObjectIDFromHex("652f1a...")
filter := bson.M{"_id": bson.M{"$gte": oid}} Defensive patterns
Strategy: try-catch
Validate before calling
// validate filter and projection before reading
if err := coll.FindOne(ctx, filter, opts).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
return err
} Try / catch
cursor, err := getCursor(ctx, fn, filter)
if err != nil {
return fmt.Errorf("read failed for range %v: %w", r, err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- error finding document ID to split on: %w
- fraction must be between 0 and 1
- bundle size must be greater than 0
- batch size must be greater than 0
- error encoding BSON: %w
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/87128b6ca2a96623.
Report an issue: GitHub.