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

Possible to create documents with empty field names

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc1
    • Component/s: None
    • None
    • ALL

      The documents can still be queried but the field cannot be indexed.

      ren@ren-desktop ~/mongo-copy $ ./mongo --writeMode legacy
      MongoDB shell version: 2.6.0-rc1-pre-
      connecting to: test
      > db.user.drop()
      true
      > db.user.insert({ a: { "": 2 }})
      > db.user.find()
      { "_id" : ObjectId("531f798aa676eb5ad3d44332"), "a" : { "" : 2 } }
      > db.user.insert( { "": 2 })
      > db.user.find()
      { "_id" : ObjectId("531f798aa676eb5ad3d44332"), "a" : { "" : 2 } }
      { "_id" : ObjectId("531f7a27a676eb5ad3d44333"), "" : 2 }
      

      Shell session continued, using write commands

      ren@ren-desktop ~/mongo-copy $ ./mongo
      MongoDB shell version: 2.6.0-rc1-pre-
      connecting to: test
      > db.user.insert( { "": 3 })
      WriteResult({ "nInserted" : 1 })
      > db.user.find()
      { "_id" : ObjectId("531f798aa676eb5ad3d44332"), "a" : { "" : 2 } }
      { "_id" : ObjectId("531f7a27a676eb5ad3d44333"), "" : 2 }
      { "_id" : ObjectId("531f7a3248b214d47bdddd04"), "" : 3 }
      > db.user.update({ }, { "": 4 })
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      > db.user.find()
      { "_id" : ObjectId("531f798aa676eb5ad3d44332"), "" : 4 }
      { "_id" : ObjectId("531f7a27a676eb5ad3d44333"), "" : 2 }
      { "_id" : ObjectId("531f7a3248b214d47bdddd04"), "" : 3 }
      > db.user.ensureIndex({ "": 1 })
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 67,
      		"errmsg" : "bad index key pattern { : 1.0 }: Index keys cannot be an empty field."
      	}
      })
      > db.user.ensureIndex({ "a.": 1 })
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 67,
      		"errmsg" : "bad index key pattern { a.: 1.0 }: Index keys cannot contain an empty field."
      	}
      })
      > db.user.find({ "": 3 })
      { "_id" : ObjectId("531f7a3248b214d47bdddd04"), "" : 3 }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            randolph@mongodb.com Randolph Tan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: