[DOCS-7935] db.collection.update discrepancy with upsert Created: 21/May/16  Updated: 11/Jan/17  Resolved: 07/Jul/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Task Priority: Minor - P4
Reporter: Kevin Arhelger Assignee: Jonathan DeStefano
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:
Days since reply: 7 years, 31 weeks, 6 days ago

 Description   

https://docs.mongodb.com/manual/reference/method/db.collection.update/#behavior

It appears that

db.collection.update({_id:null}, {field"test"}, {upsert:true})

might be implicitly rewritten as

db.collection.update({_id:null}, {$set: {field"test"}}, {upsert:true})

resulting in unexpected behavior.

This is probably worth testing in an older version (is the behavior consistent in 2.6.1?).



 Comments   
Comment by Githook User [ 07/Jul/16 ]

Author:

{u'username': u'jdestefano-mongo', u'name': u'jonathan', u'email': u'jonathan.destefano@10gen.com'}

Message: DOCS-7935 Added upsert caveat that if querying on a specific value for _id without update operators and the upsert occurs, the _id will be added as part of the new document. -JD

DOCS-7935 Changed language for db.collection.update. Added that update() and findAndModify() handle upserts similarly. Updated parameter files to reflect upsert findings. Removed incorrect statements for findOneAndReplace(). - JD

DOCS-7935 Fixed incorrectly named parameter.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/c3aebcf43793034d4a6ba76ff65a40a79dcb9996

Comment by Githook User [ 07/Jul/16 ]

Author:

{u'username': u'jdestefano-mongo', u'name': u'jonathan', u'email': u'jonathan.destefano@10gen.com'}

Message: DOCS-7935 Added upsert caveat that if querying on a specific value for _id without update operators and the upsert occurs, the _id will be added as part of the new document. -JD

DOCS-7935 Changed language for db.collection.update. Added that update() and findAndModify() handle upserts similarly. Updated parameter files to reflect upsert findings. Removed incorrect statements for findOneAndReplace(). - JD

DOCS-7935 Fixed incorrectly named parameter.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/c3aebcf43793034d4a6ba76ff65a40a79dcb9996

Comment by Githook User [ 07/Jul/16 ]

Author:

{u'username': u'jdestefano-mongo', u'name': u'jonathan', u'email': u'jonathan.destefano@10gen.com'}

Message: DOCS-7935 Added upsert caveat that if querying on a specific value for _id without update operators and the upsert occurs, the _id will be added as part of the new document. -JD

DOCS-7935 Changed language for db.collection.update. Added that update() and findAndModify() handle upserts similarly. Updated parameter files to reflect upsert findings. Removed incorrect statements for findOneAndReplace(). - JD

DOCS-7935 Fixed incorrectly named parameter.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/c3aebcf43793034d4a6ba76ff65a40a79dcb9996

Comment by Jonathan DeStefano [ 17/Jun/16 ]

It turns out that if the update parameter contains only field and value pairs those will be set. In addition, if the query parameter contains a specific value for the "_id" field, the "_id" field will be set in the new document, but any remaining query field and value pairs will be discarded.

Verified in 2.6.1 and 3.2.7

Comment by Jonathan DeStefano [ 17/Jun/16 ]

Verified Abdul's comment, <update> and <query> parameters are used whether and update operator is used or not. Will work on testing in 2.6.1 as suggested.

Generated at Thu Feb 08 07:55:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.