[SERVER-12996] Able to insert and upsert documents with empty field name Created: 03/Mar/14  Updated: 10/Dec/14  Resolved: 04/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0-rc0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Greg Studer
Resolution: Duplicate Votes: 0
Labels: 26qa
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
Operating System: ALL
Participants:

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



 Comments   
Comment by Greg Studer [ 04/Mar/14 ]

Not strictly a write command issue. Non-regression.

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