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

An update with $pullAll behaves differently with timeseries vs non-timeseries collections

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Integration
    • ALL
    • Execution Team 2024-02-05

      Results are different when running the same update on a timeseries collection vs. regular collection with the same documents. Steps which reproduce are as follows:

      For the control:

      Insert these documents:

      db.controlColl.insert({ _id: 17866, time: new Date("2019-11-29T15:21:52.056Z"),"tag": {"str": "Saint Martin intermediate", "obj": null}})
      db.controlColl.insert({ _id: 19289, time: new Date("2019-01-14T09:44:22.760Z"),"tag": {"str": "California dot-com project", "obj": {_id: 19290, "array": [Infinity], "obj": {}}}})

      Running this update:

      db.controlColl.updateMany({}, {"$pullAll": {"tag.obj.array": [false, NumberDecimal("Infinity")]}}, {multi:true})

      This gives us a writeError.

      db.controlColl.find({})
      { "time" : ISODate("2019-01-14T09:44:22.760Z"), "tag" : { "obj" : { "_id" : 19290, "array" : [ Infinity ], "obj" : {  } }, "str" : "California dot-com project" }, "_id" : 19289 }
      { "time" : ISODate("2019-11-29T15:21:52.056Z"), "tag" : { "obj" : null, "str" : "Saint Martin intermediate" }, "_id" : 17866 }

      When running the same update on a timeseries collection with the same documents the result is different:

      db.createCollection("timeColl", {timeseries: {timeField: 'time', metaField: 'tag'}})
      db.timeColl.insert({ _id: 17866, time: new Date("2019-11-29T15:21:52.056Z"),"tag": {"str": "Saint Martin intermediate", "obj": null}})
      db.timeColl.insert({ _id: 19289, time: new Date("2019-01-14T09:44:22.760Z"),"tag": {"str": "California dot-com project", "obj": {_id: 19290, "array": [Infinity], "obj": {}}}})
      db.timeColl.updateMany({}, {"$pullAll": {"tag.obj.array": [false, NumberDecimal("Infinity")]}}, {multi:true})
      db.timecoll5.find({})
      

      results:

      { "time" : ISODate("2019-01-14T09:44:22.760Z"), "tag" : { "obj" : { "_id" : 19290, "array" : [ ], "obj" : {  } }, "str" : "California dot-com project" }, "_id" : 19289 }
      { "time" : ISODate("2019-11-29T15:21:52.056Z"), "tag" : { "obj" : null, "str" : "Saint Martin intermediate" }, "_id" : 17866 }

      We can see that for the document with "_id" : 19289, tag.obj.array in the control case is [Infinity] while in the timeseries case is an empty array [].

      Calling the update on the document with "_id" : 17866 causes a write error since we are trying to traverse tag.obj.array but tag.obj is null. If we run the same test but only with the one document which causes no write errors, the results are the same in both the timeseries and control case:

      { "_id" : 19289, "time" : ISODate("2019-01-14T09:44:22.760Z"), "tag" : { "str" : "California dot-com project", "obj" : { "_id" : 19290, "array" : [ ], "obj" : {  } } } }

      with tag.obj.array being the empty array [].

      This implies we are treating write errors differently with updates in timeseries vs. without; It seems like we are continuing with the updates normally in timeseries even after a write error, but that for a normal collection we potentially stop the updates from occurring.

       

            Assignee:
            yuhong.zhang@mongodb.com Yuhong Zhang
            Reporter:
            naama.bareket@mongodb.com Naama Bareket
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: