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

Possible to create documents with empty field names

    XMLWordPrintable

    Details

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

      Description

      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 }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              renctan Randolph Tan
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: