[SERVER-13533] Misformed update command options Created: 09/Apr/14  Updated: 10/Dec/14  Resolved: 10/Apr/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.8, 2.4.10
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Mark Unsworth Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

With a prepopulated collection of > 1 documents execute the following command:

db.my_collection.update({},{$set:{field_name:"new_value"}}, multi=true)

now check the documents in the collection. None will have been updated

Participants:

 Description   

If the options section of an update command is misformed the update fails and no error message is shown.

If an equals sign is used in the place of a colon for the update options values, the update fails to execute silently.



 Comments   
Comment by Asya Kamsky [ 10/Apr/14 ]

You have to pass valid JSON document, see examples here:

http://docs.mongodb.org/manual/reference/method/db.collection.update/#example-update-multi

Comment by Mark Unsworth [ 10/Apr/14 ]

ok - i see now that it's just updating one at a time. The collection I was running the command on was fairly large so the one document changed wasn't noticed.

Is the use of the multi=true not invalid? If i change to multi:true i get an unexpected token error:

    > db.test.update({},{"$set":{field_value:"new_value"}}, multi:true)
    Thu Apr 10 16:40:10.035 SyntaxError: Unexpected token :

I realise that to get it to function it needs to be in braces, my point is more on whether the previous example should also throw an exception rather than update a single document

Comment by Asya Kamsky [ 10/Apr/14 ]

FYI, same result on 2.4.8

> db.test.find()
{ "_id" : ObjectId("53462beccc88244a52ea7e70") }
{ "_id" : ObjectId("53462bedcc88244a52ea7e71") }
Fetched 2 record(s) in 0ms
> db.test.update({},{$set:{field_name:"new_value"}}, multi=true)
Updated 1 existing record(s) in 2ms
> db.test.find()
{ "_id" : ObjectId("53462bedcc88244a52ea7e71") }
{ "_id" : ObjectId("53462beccc88244a52ea7e70"), "field_name" : "new_value" }
Fetched 2 record(s) in 1ms
> db.version()
2.4.8
>

Comment by Asya Kamsky [ 10/Apr/14 ]

I tried this and the update worked successfully (on one object only)

test@local(2.6.0) > db.test.find()
{ "_id" : ObjectId("53462b3b9f261180216aa4c8") }
{ "_id" : ObjectId("53462b3d9f261180216aa4c9") }
Fetched 2 record(s) in 5ms
test@local(2.6.0) > db.test.update({},{$set:{field_name:"new_value"}}, multi=true)
Updated 1 existing record(s) in 4ms
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
test@local(2.6.0) > db.test.find()
{ "_id" : ObjectId("53462b3b9f261180216aa4c8"), "field_name" : "new_value" }
{ "_id" : ObjectId("53462b3d9f261180216aa4c9") }
Fetched 2 record(s) in 1ms

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