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

Able to insert and upsert documents with empty field name

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.6.0-rc0
    • Fix Version/s: None
    • Component/s: Write Ops
    • Labels:
    • Operating System:
      ALL

      Description

      Results are inconsistent

      // With insert the empty field is created.
      > db.foo.insert({'': 'not allowed'})
      WriteResult({ "nInserted" : 1 })
      > db.foo.find()
      { "_id" : ObjectId("5314b690dd98b8b9decc41a7"), "" : "not allowed" }
      > db.foo.drop()
      true
       
      // Replace-style upsert allows "" field names
      > db.foo.find()
      { "_id" : ObjectId("5314b7b03a6a695da8595d60") }
      > db.foo.drop()
      true
      > db.foo.update({}, {'': 'not allowed'}, {upsert:true})
      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 1,
              "nModified" : 0,
              "_id" : ObjectId("5314b7d03a6a695da8595d61")
      })
      > db.foo.find()
      { "_id" : ObjectId("5314b7d03a6a695da8595d61"), "" : "not allowed" }
       
      // Other upserts don't allow empty fields:
      > db.foo.drop()
      true
      > db.foo.update({'': 'not allowed'}, {$set:{a:1}}, {upsert:true})
      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 56,
                      "errmsg" : "An empty update path is not valid."
              }
      })
      > db.foo.drop()
      false
      > db.foo.update({}, {$set:{"":1}}, {upsert:true})
      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 56,
                      "errmsg" : "An empty update path is not valid."
              }
      })

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              greg_10gen Greg Studer
              Reporter:
              redbeard0531 Mathias Stearn
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: