-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Change streams
-
DB Integration & Observability
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Problem
On a sharded collection, a change stream opened with fullDocument: "updateLookup" fails when it reaches an update to a document whose shard-key value is BSON undefined:
Executor error during getMore :: caused by :: cannot compare to undefined (BadValue, code 2)
The same event fails again on resume, so the stream cannot advance past it.
Reproduction
Observed on 7.0.46, sharded cluster, legacy mongo shell connected to mongos (the legacy shell writes JS undefined as BSON undefined):
sh.enableSharding("test"); sh.shardCollection("test.foo", {v: 1}); const cs = db.foo.watch([], {fullDocument: "updateLookup"}); db.foo.insert({_id: 1, v: undefined}); db.foo.update({_id: 1, v: {$type: "undefined"}}, {$inc: {f: 1}}); // nModified: 1 cs.next(); // fails: "cannot compare to undefined"
Cause
The post-image lookup uses the event's documentKey directly as a query predicate. At master, CommonMongodProcessInterface::doLookupSingleDocument runs $match: documentKey (src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp). For {{documentKey:
{v: undefined, _id: 1}}} that is an equality on undefined, which the matcher rejects (ComparisonMatchExpression: "cannot compare to undefined").
Expected
The lookup should find the document, e.g. by matching an undefined shard-key value by type rather than by equality.
Related: SERVER-105706 (documentKey values are not safe to use as query predicates).
- is related to
-
SERVER-105706 Change event's documentKey lacks null/missing values
-
- Needs Scheduling
-
-
SERVER-140035 Shard-key update that changes the owning shard fails if the document has a top-level BSON undefined field
-
- Needs Scheduling
-
-
DRIVERS-3682 Add logic to convert change stream doc key to query filter
-
- Investigating
-
- related to
-
SERVER-137213 fullDocument: "updateLookup" returns the wrong document when the event's documentKey contains a regexp-valued shard key field
-
- Needs Merge
-
-
SERVER-140035 Shard-key update that changes the owning shard fails if the document has a top-level BSON undefined field
-
- Needs Scheduling
-
-
DRIVERS-3682 Add logic to convert change stream doc key to query filter
-
- Investigating
-