[CSHARP-58] MongoCollection<T>.FindAndModify doesn't work when updating an whole document. Created: 26/Aug/10  Updated: 19/Oct/16  Resolved: 11/Nov/10

Status: Closed
Project: C# Driver
Component/s: SAMUS
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Gabriel Duford Assignee: Sam Corder
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

samus-mongodb-csharp-85d3524
MongoDB 1.6



 Description   

MongoCollection<T>.FindAndModify doesn't work when updating an whole document.
The following code does no change to the database:
Document query =
new Document()
{

{ "_id", new Oid("4c7541d563804c1680000001") }

};
mongo["DB"].GetCollection<MyClass>("Collection").FindAndModify(theModifiedInstance, query);

On the other side, the following (supposedly equivalent) works fine:
Document command =
new Document()
{

{"findandmodify", "Collection"}

,

{"query", query}

,

{"update", theModifiedInstance}

,

{"new", false}

,

{"upsert", false}

};
mongo["DB"].SendCommand(command);

The bug seems to be on line 217 of MongoCollection_1.cs (as per version given in "Environment"):

{"update", EnsureUpdateDocument(document)}

EnsureUpdateDocument will create a new document with a $set. Clearly, from the example above, this should not be done.



 Comments   
Comment by Steve Wagner [ 11/Nov/10 ]

Migrated to https://github.com/mongodb-csharp/mongodb-csharp/issues/issue/25

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