[SERVER-28383] Shell bulk.updateOne allows replacement Created: 17/Mar/17  Updated: 27/Oct/23  Resolved: 29/Jun/20

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

Type: New Feature Priority: Major - P3
Reporter: David Golden Assignee: DO NOT USE - Backlog - Dev Tools
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-10009 Comment on: "manual/reference/method/... Closed
related to SERVER-13092 shell bulk API replaceOne behaves lik... Closed
related to SERVER-48780 bulkWrite() in mongo shell does not c... Closed
related to SERVER-24002 Consider deprecating the bulk API in ... Closed
Assigned Teams:
Developer Tools
Participants:

 Description   

Normal "updateOne" requires "$" modifiers. However, bulk operation updateOne will allow a replacement (and this is documented). This violates the specification for bulk update (see test case 3).

This is inconsistent with updateOne in the shell and inconsistent with driver behaviors. We had a mongodb-user question because someone expected the (legacy) C++ driver behavior to match the shell's behavior.

Example (from kay.kim in discussions in DOCS-10009):

> db.items.insert( { } )
WriteResult({ "nInserted" : 1 })
> var bulk = db.items.initializeUnorderedBulkOp();
> bulk.find( { item: null } ).updateOne(
...    {
...       item: "TBD",
...       points: 0,
...       inStock: true,
...       status: "I"
...    }
... );
> bulk.execute();
BulkWriteResult({
	"writeErrors" : [ ],
	"writeConcernErrors" : [ ],
	"nInserted" : 0,
	"nUpserted" : 0,
	"nMatched" : 1,
	"nModified" : 1,
	"nRemoved" : 0,
	"upserted" : [ ]
})
 
> db.items.find()
{ "_id" : ObjectId("58cbffadfb324641a8922d60"), "item" : "abc123", "defaultQty" : 100, "status" : "A", "points" : 100 }
{ "_id" : ObjectId("58cbffadfb324641a8922d61"), "item" : "ijk123", "defaultQty" : 200, "status" : "A", "points" : 200 }
{ "_id" : ObjectId("58cbffadfb324641a8922d62"), "item" : "mop123", "defaultQty" : 0, "status" : "P", "points" : 0 }
{ "_id" : ObjectId("58cbffd3fb324641a8922d63"), "item" : "TBD", "points" : 0, "inStock" : true, "status" : "I" }

This may not be worth fixing if SERVER-24002 goes forward.



 Comments   
Comment by Jessica Sigafoos [ 29/Jun/20 ]

The new shell uses the node.js driver.  If you find that the functionality is not what you'd expect in the new shell, please file a new ticket in the MONGOSH project.

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