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

Timeseries pushes down metaField-projections that can change semantics

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 5.0.15, 6.0.4, 6.2.0-rc0
    • Affects Version/s: 5.0.7, 6.0.0-rc6
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v6.1, v6.0, v5.0
    • 9

      If a projection computes `obj` only in terms of a meta field and another field `blergh` is computed in terms of value of `obj` IN THE SAME PROJECTION, then we will push down the meta-field-only computation of `obj`. This causes `obj` to be overwritten before we can compute `blergh` causing an incorrect calculation.

      See the example below where `obj` is `obj` and `blergh` is `b`.

      db.c.drop()
      db.d.drop()
      db.createCollection("c", {timeseries: {timeField: "t", metaField: "m"}})
      db.c.insert({obj: {a: 3}, m: {}, t: new Date()})
      db.d.insert({obj: {a: 3}, m: {}, t: new Date()})
      
      db.d.aggregate([{$addFields: {obj: "$m", b: {$add: ["$obj.a", 1]}}}])
      // Correct result { "_id" : ObjectId("6285641318f6a25daf333976"), "obj" : {  }, "m" : {  }, "t" : ISODate("2022-05-18T21:24:35.843Z"), "b" : 4 }
      
      db.c.aggregate([{$addFields: {obj: "$m", b: {$add: ["$obj.a", 1]}}}])
      // incorrect result { "t" : ISODate("2022-05-18T21:24:57.873Z"), "m" : {  }, "_id" : ObjectId("6285642918f6a25daf333978"), "obj" : {  }, "b" : null }
      

            Assignee:
            hana.pearlman@mongodb.com Hana Pearlman
            Reporter:
            samuel.mercier@mongodb.com Sam Mercier
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: