[SERVER-4197] Not possible to use multiple $push statements in the same update() command Created: 02/Nov/11  Updated: 07/Mar/14  Resolved: 04/Nov/11

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.8.4, 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Marc Bastien Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

all


Operating System: ALL
Participants:

 Description   

If an update() command contains multiple $push statements, only the last one will be executed.

To reproduce:

> db.test.drop()
true
> db.test.save({_id:1, "array1":[0], "array2":["a"]})
> db.test.find()

{ "_id" : 1, "array1" : [ 0 ], "array2" : [ "a" ] }

> db.test.update({_id:1}, {$push:

{"array1":1}

, $push:{"array2":"b"}})
> db.test.find()

{ "_id" : 1, "array1" : [ 0 ], "array2" : [ "a", "b" ] }

 Comments   
Comment by Eliot Horowitz (Inactive) [ 04/Nov/11 ]

Wrong syntax

> db.foo.drop()
true
> db.test.insert( { a : [] , b : [] } )
> db.test.update( {} , { $push : { a : 1 , b : 2 } } )
> db.test.findOne()
{
	"_id" : ObjectId("4eb3717f21e321e71a773949"),
	"a" : [
		1
	],
	"b" : [
		2
	]
}
> 

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