Home > Back-end >  How to add WriteConcern in options in MongoDB driver in C#?
How to add WriteConcern in options in MongoDB driver in C#?

Time:08-30

My task is to create the method AddUnacknowledged where I shoud add item to collection with WriteConcern.Unacknowledged in MongoDB 2.17 and C#.

In previous version there was that option and the code was simple:

GetCollection(GetCollectionName(collectionName), federatedDBKey).Add(item, WriteConcern.Unacknowledged);

In current version I am not sure how to do this as I tried:

GetCollection(GetCollectionName(collectionName), federatedDBKey).InsertOne(item, WriteConcern.Unacknowledged);

But WriteConcern.Unacknowledged should be option parameter for method InsertOne() and I can't find how to write this as option parameter. Is this possible?

CodePudding user response:

Should look like this:

GetCollection(GetCollectionName(collectionName), federatedDBKey)
  .WithWriteConcern(WriteConcern.Unacknowledged)
  .InsertOne(item);
  • Related