0

How should I know, if resulted model was upserted?

FilterDefinition<T> filter = Builders<T>.Filter.Eq("_id", modelId);
UpdateDefinition<T> update = ... ;

var opts = new FindOneAndUpdateOptions<T>()
{
    IsUpsert = true,
    ReturnDocument = ReturnDocument.After
};

var model = this.Collection.FindOneAndUpdate(filter, update, opts);
Tomas Petovsky
  • 285
  • 4
  • 14
  • See here: http://stackoverflow.com/questions/13955212/check-if-mongodb-upsert-did-an-insert-or-an-update – dyouberg Nov 01 '16 at 19:43
  • @dyouberg thank you, but the question was for mongodb c# driver, not the mongodb itself. I could not find any suitable method, that can update/upsert single document, based on UpdateDefinition and returns not just the resulting model, but also an information, whether that model was upserted. – Tomas Petovsky Nov 02 '16 at 06:18

0 Answers0