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

Upsert with $-positional operator can create bad documents

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.3.2
    • None
    • Write Ops
    • None
    • ALL

    Description

      From a recent question in training: "what happens if you try to use the positional operator with upsert?". It appears it can create an invalid document with a dollarsign in the field name:

      db.foo.update(

      { 'x.a' : 6 }

      , { $set :

      { 'x.$.b' : -5 }

      }, true )
      db.foo.find().pretty()
      {
      "_id" : ObjectId("4f1724449afa61972cf8ef0b"),
      "x" : {
      "$" :

      { "b" : -5 }

      ,
      "a" : 6
      }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            richard.kreuter Richard Kreuter (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: