[SERVER-14593] Empty update deletes a record Created: 17/Jul/14  Updated: 17/Jul/14  Resolved: 17/Jul/14

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

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

Operating System: ALL
Steps To Reproduce:

Start with a record:

{ "_id" : ObjectId("53c7cf02449a3606a7037755"), "guid" : NumberLong("279172874564"), "region_id" : "US"}

Call update on the collection (this example is in python)

collection.update({'guid': 279172874564}, {}, safe=True, w=1, wtimeout=250)

Observe that the record has now been cleared.

{ "_id" : ObjectId("53c7cf02449a3606a7037755") }

The expected behavior is that this is treated as a no-op.

Participants:

 Description   

mongo 2.6.1
pymongo 2.5.1

Calling Collection.update with an empty dictionary will delete all but the _id field.



 Comments   
Comment by Scott Hernandez (Inactive) [ 17/Jul/14 ]

This is how replacement style updates work.

http://docs.mongodb.org/manual/reference/method/db.collection.update/#replace-a-document-entirely

Since the _id field is immutable and cannot be removed it is the only one left after replacing the document.

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