[SERVER-7063] Blank key in embedded doc seems to prevent findAndModify from applying modifier Created: 18/Sep/12  Updated: 03/Jan/18  Resolved: 20/Nov/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.0.7, 2.2.0
Fix Version/s: 2.5.4

Type: Bug Priority: Major - P3
Reporter: Michael O'Brien Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Participants:
Case:

 Description   

Reproduce with this (ops must be applied in order):

 
db.test.insert({'name': 'TEST'})
db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test.one': 1}}, new:true})
db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test..foo': 1}}, new:true})
db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test.two': 1}}, new:true})

The second findAndModify statement creates an embedded doc under a blank key ("").
The subsequent call to findAndModify in the last line, even when executed multiple times, never seems to actually increment the counter.



 Comments   
Comment by Scott Hernandez (Inactive) [ 20/Nov/13 ]

You can no longer create that empty field. Even if I use black-magic to get a doc in there with an empty field name it still works:

> db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test..two': 1}}, new:true})
2013-11-20T14:02:51.557-0500 findAndModifyFailed failed: {
	"errmsg" : "exception: The update path 'counters.test..two' contains an empty field, which is not allowed.",
	"code" : 16840,...
 
> db.test.remove()
... do magic...
> db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test.two': 1}}, new:true})
{
	"_id" : 1,
	"name" : "TEST",
	"counters" : {
		"test" : {
			"one" : 1,
			"" : {
				"two" : 0
			},
			"two" : 1
		}
	}
}
test1:PRIMARY> db.test.findAndModify({query:{'name': 'TEST'}, update:{'$inc': {'counters.test.two': 1}}, new:true})
{
	"_id" : 1,
	"name" : "TEST",
	"counters" : {
		"test" : {
			"one" : 1,
			"" : {
				"two" : 0
			},
			"two" : 2
		}
	}
}

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