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

$project field that references time-series meta field can be referenced by second $project field

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.3.2, 6.0.0-rc0, 5.0.7
    • Affects Version/s: 6.0.0, 5.0.5, 5.2.1, 5.3.0-rc2
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v5.3, v5.2, v5.0
    • Hide
      db.dropDatabase();
      db.createCollection("tsColl", {timeseries: {timeField: 'time', metaField: 'x'}});
      
      var doc = {time: new Date("2019-10-11T14:39:18.670Z"), x: 5};
      
      db.tsColl.insert(doc);
      db.regColl.insert(doc);
      
      var pipeline = [{$project: {_id: 0, a: "$x", b: "$a"}}];
      var tsDoc = db.tsColl.aggregate(pipeline).toArray();
      var regDoc = db.regColl.aggregate(pipeline).toArray();
      assert.eq(tsDoc,regDoc);
      

      The above produces the following error:

      Error: [[ { "a" : 5, "b" : 5 } ]] != [[ { "a" : 5 } ]] are not equal
      
      Show
      db.dropDatabase(); db.createCollection( "tsColl" , {timeseries: {timeField: 'time' , metaField: 'x' }}); var doc = {time: new Date( "2019-10-11T14:39:18.670Z" ), x: 5}; db.tsColl.insert(doc); db.regColl.insert(doc); var pipeline = [{$project: {_id: 0, a: "$x" , b: "$a" }}]; var tsDoc = db.tsColl.aggregate(pipeline).toArray(); var regDoc = db.regColl.aggregate(pipeline).toArray(); assert .eq(tsDoc,regDoc); The above produces the following error: Error: [[ { "a" : 5, "b" : 5 } ]] != [[ { "a" : 5 } ]] are not equal
    • QO 2022-03-07, QO 2022-03-21
    • 122

      See included reproducer. In a $project stage like {$project: {a: "$meta", b: "$a"}}, the "$a" expression should only be able to reference a value in the original document passed to the $project stage. For time-series collections, if it references the name of a different projection field, where that field references the meta field value, then it is populated with the metadata value as well.

            Assignee:
            james.wahlin@mongodb.com James Wahlin
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: