0

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?

NewCSharp
  • 45
  • 6
  • Does this answer your question? [Understanding WriteConcern in MongoDB C#](https://stackoverflow.com/questions/26660950/understanding-writeconcern-in-mongodb-c-sharp) – Mihail Aug 29 '22 at 14:15
  • @Mihail Yes, before I asked question I saw that. Also, answer I got below is correct and it is not written in that thread so we can leave this question too. Thank you for your time and help – NewCSharp Aug 30 '22 at 11:37

1 Answers1

2

Should look like this:

GetCollection(GetCollectionName(collectionName), federatedDBKey)
  .WithWriteConcern(WriteConcern.Unacknowledged)
  .InsertOne(item);
Chase
  • 2,206
  • 1
  • 13
  • 17
  • 1
    Yes. The whole time I changed the places for WithWriteConcern and InsertOne and it wasn't working. Stupid mistake by me. Thank you very much for your help – NewCSharp Aug 29 '22 at 14:22