I tested that this works. Thanks.
this. Sad, since this is way simpler than the creating the
On Aug 18, 11:10 am, Evo <
evopatr...@gmail.com> wrote:
> Take a look at the overload for the Update method on Collection that
> takes a document, a selector, and an UpdateFlags. You will have to do
> something similar to...
>
> database.GetCollection<Document>("MyCollection").Update(new
> Document("FieldToIncrement", new Document("$inc", 1)), new Document(),
> UpdateFlags.Upsert)
>
> I didn't test that but should be something similar...
>
> On Aug 17, 7:21 pm, Gabriel Duford <
gabrielduf...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
> > 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. (