[SERVER-10009] Order of operators matters when using $each with $push Created: 24/Jun/13  Updated: 07/Mar/14  Resolved: 07/Oct/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.4
Fix Version/s: 2.5.2

Type: Bug Priority: Major - P3
Reporter: E.J. Bensing Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12.04 LTS


Issue Links:
Related
related to DOCS-2075 Order of operators no longer matters ... Closed
is related to SERVER-6399 Refactor update() code Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.test_update.insert({name: "2.4"})
// this works
db.test_update.update({name :"2.4"}, { $push: { n: { $each: [{x:10},{x:4}, {x:1}] , $slice: -1 , $sort: { x:1 }}}})
db.test_update.findOne()
{
	"_id" : ObjectId("51c8a7f31c7a4e0a10e4f14a"),
	"n" : [
		{
			"x" : 10
		}
	],
	"name" : "2.4"
}
// reset things
db.test_update.update({name:"2.4"},{ $set : { n : [] }})
// this does not work
db.test_update.update({name :"2.4"}, { $push: { n: { $slice : -1, $each: [{x:10},{x:4}, {x:1}] , $sort: { x:1 }}}})
db.test_update.findOne()
{
	"_id" : ObjectId("51c8a7f31c7a4e0a10e4f14a"),
	"n" : [
		{
			"$slice" : -1,
			"$each" : [
				{
					"x" : 10
				},
				{
					"x" : 4
				},
				{
					"x" : 1
				}
			],
			"$sort" : {
				"x" : 1
			}
		}
	],
	"name" : "2.4"
}

Participants:

 Description   

Essentially, when using $each with $push, the $each operator must come before any other operands such as $slice or $sort. This is breaking in many languages since dicts/objects do not maintain a consistent key ordering.



 Comments   
Comment by Scott Hernandez (Inactive) [ 07/Oct/13 ]

The new update code is no longer dependent on the order of the fields.

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