[CSHARP-1597] FindOneAndUpdateAsync with empty update definition erases document fields Created: 09/Mar/16  Updated: 18/May/16  Resolved: 11/Mar/16

Status: Closed
Project: C# Driver
Component/s: Operations
Affects Version/s: 2.0
Fix Version/s: 2.2.4

Type: Bug Priority: Major - P3
Reporter: Nick Abalov [X] Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When calling FindOneAndUpdateOptions with update definition which is combination of items of update definitions list if the list is empty, then all document fields, except for id gets erased.

var updates = new List<UpdateDefinition<Region>>();
_collection.FindOneAndUpdateAsync(filter, Builders<Region>.Update.Combine(updates), new FindOneAndUpdateOptions<Region>
                {
                    ReturnDocument = ReturnDocument.After,
                });



 Comments   
Comment by Githook User [ 11/Mar/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1597: empty updates should throw exceptions so as not to inadvertantly overwrite entire documents.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/72c139365e4a1852dea58a9c0a07949b123deac8

Comment by Githook User [ 11/Mar/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1597: empty updates should throw exceptions so as not to inadvertantly overwrite entire documents.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/6477cb5acd43a8c5712a43171ec568f5a429e6c2

Comment by Craig Wilson [ 09/Mar/16 ]

Hi Nick,

I can confirm this bug. Thanks for reporting. We'll see what we can do, but it appears to be a design issue that prevents us from validating empty documents in the same way we do other validations.

Craig

Generated at Wed Feb 07 21:40:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.