Details
-
Bug
-
Resolution: Won't Fix
-
Major - P3
-
None
-
1.9
-
None
Description
The FindAndModify method does not inspect server errors to see if the error is in fact a duplicate key error. Instead the error is re-thrown as a MongoCommandException, thus leaving it to the caller to inspect the exception and determine if it is a duplicate key error. The Exception thrown looks like:
MongoDB.Driver.MongoCommandException : Command 'findAndModify' failed: exception: E11000 duplicate key error index: MeterProfileRepositoryTest_635354843219333625.MeterProfile.$id dup key: { : "1234" } (response: { "value" : null, "errmsg" : "exception: E11000 duplicate key error index: MeterProfileRepositoryTest_635354843219333625.MeterProfile.$id dup key: { : \"1234\" }", "code" : 11000, "ok" : 0.0 })
The duplicate key can happen when using FindAndModify with a query using the "_id" field and some other field in combination with an "Update.Replace" and "upsert = true".