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

Update Aggregation Pipeline values that start with $ resolve to undefined

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.3.6
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      Hey, this is Thomas with the Node.js driver team!

      I had a user report this case and I'm passing it up. This seems like odd behavior to me, perhaps there's a way of escaping that I'm not aware of.

      For some reason when updateOne is passed a pipeline that `$sets` and the values in that document start with a `$` an update does not take place, it actually removes the property if it exists. If not it will do nothing. I've tried updating strings like `a$a` and they work as expected. 

      Here's an example from the shell (4.3.6)

      > db.meow.insert({ name: 'tom' })
      WriteResult({ "nInserted" : 1 })
      > const cat = db.meow.findOne()
      > db.meow.updateOne({ _id: cat._id }, [{ $set: { password: '$anything' }}])
      { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }
      > db.meow.findOne()
      { "_id" : ObjectId("5ef65b23f330c5e7e431c975"), "name" : "tom" }
      > db.meow.updateOne({ _id: cat._id }, [{ $set: { password: 'anything' }}])
      { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
      > db.meow.findOne()
      {
       "_id" : ObjectId("5ef65b23f330c5e7e431c975"),
       "name" : "tom",
       "password" : "anything"
      }
      

            Assignee:
            asya.kamsky@mongodb.com Asya Kamsky
            Reporter:
            thomas.reggi@mongodb.com Thomas Reggi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: