Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-90871

Document::getNestedFieldNonCaching returns incorrect result

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.0-rc7
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0
    • 200

      Minimal reproduction script:

      db.coll.drop();
      assert.commandWorked(db.coll.insertMany([
          {_id: 1, "obj": {"obj": {} } },
          {_id: 2 },
      ]));
      const result = db.coll.aggregate([{$addFields: {"obj": null}}, {$sort: {"obj.obj": 1, _id: 1}}]).toArray();
      jsTestLog(result);
      

      Incorrect result:

      [jsTest] ----
      [jsTest] [ { "_id" : 2, "obj" : null }, { "_id" : 1, "obj" : null } ]
      [jsTest] ----
      

      Note that the order of returned documents is wrong. The document is marked as modified after passing the $addFields stage. The top-level "obj" field is in the document cache. Document::getNestedFieldNonCachingHelper function ignores the cache and returns the "obj.obj" field in the backing BSON.

            Assignee:
            rui.liu@mongodb.com Rui Liu
            Reporter:
            rui.liu@mongodb.com Rui Liu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: