[SERVER-39975] update accepts true or an options document Created: 06/Mar/19  Updated: 10/Jul/19  Resolved: 07/May/19

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 4.0.6
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Frederik Gelder Assignee: Gabriel Russell (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to NODE-2088 Inconsistent field names in BulkWrite... Closed
is related to SERVER-28397 shell helper for update must pass thr... Backlog
Operating System: ALL
Steps To Reproduce:

create a database that has a collection called user_data (name doesnt matter)

execute command:

db.user_data.updateOne({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true)

you will get

{ "acknowledged" : true, "matchedCount" : 0, "modifiedCount" : 0 }

execute command:

db.user_data.update({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true)

you will get

WriteResult({
 "nMatched" : 0,
 "nUpserted" : 1,
 "nModified" : 0,
 "_id" : ObjectId("5c7f1e7b66535aa5d0c469d7")
})

i would expect updateOne to do the same as update

Sprint: Dev Tools 2019-05-20
Participants:

 Description   

for my project i needed to upsert into a set of values. i noticed that upserting didnt work when i was using updateOne, but it worked when i used update. this was done in the terminal, running mongodb shell 4.0.6.



 Comments   
Comment by Gabriel Russell (Inactive) [ 07/May/19 ]

fredlllll The update command is older then the updateOne command. When the update command originally appeared, it had the api that you found on stack overflow. Eventually we realized that that api had limitations so we added a new bettter api and stopped recommending or documenting the old api. We left it in because we didn't want to break any existing code that people wrote and were using. Subsequently we developed updateOne and because there of course were not any prior uses of that command, we only wrote it for the newer api.

Thank you for your bug report, but this looks to working correctly.

Gabriel Russell

Comment by Frederik Gelder [ 07/Mar/19 ]

so does this basically mean "user error"? i dont see it specified in the docs that a true can mean upsert too. i just saw the queries on stackoverflow using a true for upserting and it worked for update, so i didnt question it

Comment by Eric Sedor [ 06/Mar/19 ]

See update and updateOne for the documented parameters.

Currently, update not only accepts an options document (which may or may not include {upsert:true}, it can also accept true to specify an upsert.

Generated at Thu Feb 08 04:53:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.