ExportXMLWordPrintableJSON

    • 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).

            Assignee:
            Jan Steemann
            Reporter:
            Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: