[SERVER-12674] Possible to end up with an empty string property which can lead to silent troubles Created: 10/Feb/14  Updated: 07/Mar/14  Resolved: 11/Feb/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.6
Fix Version/s: None

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

Issue Links:
Related
related to SERVER-2051 Disallow empty string keys Open
Operating System: ALL
Steps To Reproduce:

To get a nameless property from shell:

db.testGuy.insert({Name: "Test1"})
db.testGuy.update({Name: "Test1"}, {$inc: {"TestObject..Value": 1}})
db.testGuy.findOne({Name: "Test1"})
{
        "Name" : "Test1",
        "TestObject" : {
                "" : {
                        "Value" : 1
                }
        },
        "_id" : ObjectId("52f93e1be856377627267033")
}

Yikes! Now what happens if I try to mess around with TestObject?

db.testGuy.update({Name: "Test1"}, {$inc: "TestObject.TestProperty.Value": 1}})
db.testGuy.findOne({Name: "Test1"})
{
        "Name" : "Test1",
        "TestObject" : {
                "" : {
                        "Value" : 1
                }
        },
        "_id" : ObjectId("52f93e1be856377627267033")
}
db.testGuy.update({Name: "Test1"}, {$inc: {VeryCoolValue: 1, "TestObject.AnotherValue": 1}})
{
        "Name" : "Test1",
        "TestObject" : {
                "" : {
                        "Value" : 1
                }
        },
        "VeryCoolValue" : 1,
        "_id" : ObjectId("52f93e1be856377627267033")
}

That last one shows the danger of this kind of situation: the updates partially complete and report success even though half of my update actually failed.

Participants:

 Description   

Several operations ($set and $inc tested, there may be others) can create a nameless property which becomes difficult to remove and causes updates to partially and silently fail.



 Comments   
Comment by Scott Hernandez (Inactive) [ 11/Feb/14 ]

This was fixed in the update refactoring for 2.6; this is the output from the latest dev release, 2.5.5+:

> db.testGuy.insert({Name: "Test1"})
...
> db.testGuy.update({Name: "Test1"}, {$inc: {"TestObject..Value": 1}})
SingleWriteResult({
	"writeErrors" : [
		{
			"index" : 0,
			"code" : 16840,
			"errmsg" : "The update path 'TestObject..Value' contains an empty field name, which is not allowed.",...

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