Details
-
New Feature
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
-
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