[CSHARP-57] As a developper, I want to be able to specify the "upsert" option of the FindAndModify command Created: 18/Aug/10  Updated: 19/Oct/16  Resolved: 06/Sep/10

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

Type: New Feature Priority: Major - P3
Reporter: Gabriel Duford Assignee: Steve Wagner
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Driver samus-mongodb-csharp-85d3524
MongoDB 1.6



 Description   

I am implementing some kind of serial identifier (simple incrementing counter) functionality as part of a WCF service hosted in IIS. I want to store the counters in a Mongo collection.

I use the IMongoCollection.FindAndModify with a Mo.Inc(...) document successfully when the document already exists in the collection. However, the first time my "UserFriendlyUniqueIdGenerator" service is accessed, the document doesn't exist, and I can't just check for existence and create it if it doesn't exist because that must be done atomically (race condition).

I found out in the MondoDB documentation that it is possible to specify an "upsert" option to the FindAndModify command. (http://www.mongodb.org/display/DOCS/findandmodify+Command and http://github.com/mongodb/mongo/blob/master/jstests/find_and_modify4.js) I looked at the mongodb-csharp code and this option is not exposed.

I think I can build and call the command myself and extract the result, but it would be nice if this option could be exposed by the driver in a future version. That would allow to create or increment a counter atomically.

Discussion thread: http://groups.google.com/group/mongodb-csharp/browse_thread/thread/69b1378665ea8f76/522c2cd49ec7b3af#522c2cd49ec7b3af



 Comments   
Comment by Steve Wagner [ 06/Sep/10 ]

Fixed in my branch http://github.com/lanwin/mongodb-csharp

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