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

Able to insert and upsert documents with empty field name

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Write Ops
    • Labels:
    • ALL

      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."
              }
      })
      

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: