[CSHARP-1249] What happened to MongoCollection.Save() in version 2.0 ? Created: 22/Apr/15  Updated: 05/Apr/19  Resolved: 22/Apr/15

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

Type: Task Priority: Major - P3
Reporter: Mohsen [X] Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-1560 Expose db.collection.save() as SaveAs... Closed

 Description   

Seems like the method MongoCollection.Save() in 1.x branch is removed in version 2.0.
Why ? Is it going to back in future versions !?



 Comments   
Comment by Craig Wilson [ 22/Apr/15 ]

Hi Mohsen,

We are still debating save internally. Save is not an idempotent operation, which makes retrying failures difficult. As such, drivers decided not to implement save in their new APIs. However, we do recognize the need for it, so it may come back in the future with some slightly different semantics from what currently exists in 1.x.

For now, please review the documentation here: http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/crud/writing/#update-and-replace. The ReplaceOneAsync method is what you would use as a replacement if you want to replace a document.

var entity = GetEntityToSave();
await collection.ReplaceOneAsync(x => x.Id == entity.Id, entity, new UpdateOptions { IsUpsert = true });

However, if you just created your entity, use InsertOneAsync.

I'm going to close this as Won't Fix for now. If we do implement something, another ticket will be open for the feature.

Thanks,
Craig

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