[SERVER-13138] Possible to create documents with empty field names Created: 11/Mar/14  Updated: 10/Dec/14  Resolved: 18/Mar/14

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.6.0-rc1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6852 Disallow empty path components in doc... Backlog
Related
related to SERVER-11812 Can create indexes on invalid fields ... Closed
Operating System: ALL
Participants:

 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 }



 Comments   
Comment by J Rassi [ 18/Mar/14 ]

Resolving as dup of SERVER-6852.

Generated at Thu Feb 08 03:30:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.