When performing an upsert to increment a counter value, as follows:
MongoDatabase database = MongoDatabase.Create("mongodb://localhost/test");
database.GetCollection("test").FindAndModify(null, SortBy.Null, Update.Inc("Counter", 1), true, true)
FindAndModify throws the following exception only when the collection is empty
System.InvalidOperationException
Command 'findAndModify' failed: exception: upsert mode requires query field (response:
)
This is inconsistent behaviour: no exception is thrown if the document exists (works as expected); and the mongo shell allows the same command in javascript.