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

db.Watch returns inconsistent updatedFields when working with arrays

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.15
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • ALL
    • Hide

       

      db.students.insertOne( { _id: 3, scores: [] } )
      const stream = db.students.watch()
      db.students.updateOne( { _id: 3 }, { $push: { scores: 1 } })
      stream.next()
      

      The Output of stream:

       

      {
        _id: {
          _data: '82642AD66B000000012B022C0100296E5A10045DC4B11BEA5F4319A8E7CAF46816ED71461E5F6964002B060004'
        },
        operationType: 'update',
        clusterTime: Timestamp({ t: 1680529003, i: 1 }),
        ns: { db: 'communication_chat', coll: 'students' },
        documentKey: { _id: 3 },
        updateDescription: {
          updatedFields: { scores: [ 1 ] },    <===== scores is an Array
          removedFields: [],
          truncatedArrays: []
        }
      }
      

      Performing the next $push:

       

      db.students.updateOne( { _id: 3 }, { $push: { scores: 2 } })
      stream.next()

       

       

      The Output of stream:

       

      {
        _id: {
          _data: '82642AD673000000012B022C0100296E5A10045DC4B11BEA5F4319A8E7CAF46816ED71461E5F6964002B060004'
        },
        operationType: 'update',
        clusterTime: Timestamp({ t: 1680529011, i: 1 }),
        ns: { db: 'communication_chat', coll: 'students' },
        documentKey: { _id: 3 },
        updateDescription: {
          updatedFields: { 'scores.1': 2 },    <===== scores is a object
          removedFields: [],
          truncatedArrays: []
        }
      }
      

       

       

      What to expect?

      In my opinion the first stream event should look like:

      updatedFields: { 'scores.0': 1 },

      instead of:

      updatedFields: { scores: [ 1 ] },

       

       

      Show
        db.students.insertOne( { _id: 3, scores: [] } ) const stream = db.students.watch() db.students.updateOne( { _id: 3 }, { $push: { scores: 1 } }) stream.next() The Output of stream:   {   _id: {     _data: '82642AD66B000000012B022C0100296E5A10045DC4B11BEA5F4319A8E7CAF46816ED71461E5F6964002B060004'   },   operationType: 'update' ,   clusterTime: Timestamp({ t: 1680529003, i: 1 }),   ns: { db: 'communication_chat' , coll: 'students' },   documentKey: { _id: 3 },   updateDescription: {     updatedFields: { scores: [ 1 ] }, <===== scores is an Array     removedFields: [],     truncatedArrays: []   } } Performing the next $push:   db.students.updateOne( { _id: 3 }, { $push: { scores: 2 } }) stream.next()     The Output of stream:   {   _id: {     _data: '82642AD673000000012B022C0100296E5A10045DC4B11BEA5F4319A8E7CAF46816ED71461E5F6964002B060004'   },   operationType: 'update' ,   clusterTime: Timestamp({ t: 1680529011, i: 1 }),   ns: { db: 'communication_chat' , coll: 'students' },   documentKey: { _id: 3 },   updateDescription: {     updatedFields: { 'scores.1' : 2 }, <===== scores is a object     removedFields: [],     truncatedArrays: []   } }     What to expect? In my opinion the first stream event should look like: updatedFields: { 'scores.0' : 1 }, instead of: updatedFields: { scores: [ 1 ] },    
    • QE 2023-09-18

      I expected to have a consistent return element inside the `updatedFields` when working with the watch and updateOne + $push functionality.

      When performing a coll.Watch and then a $push on an array inside the document,
      the first watch-stream returns an array in the updatedFields,
      the second watch-stream returns an object.

      What to expect

      updatedFields: { 'scores.0': 1 },

      What is actually returns

      updatedFields: { scores: [ 1 ] },

       

      Sidenotes:

      I made sure that scores is an empty array.

      I'm working with Free Mongo Cloud, in case it is important my cluster:
      typing-competition-cluster  5f562f47523b020a2093688e

      For JS this wouldn't be that of a problem, but with strictly typed languages like GOLang this is annoying to work around.

            Assignee:
            sebastien.mendez@mongodb.com Sebastien Mendez
            Reporter:
            stefan.binder89@gmail.com SpirIT N/A
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: