-
Type:
Bug
-
Resolution: Done
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 2.3
-
Component/s: API
-
None
-
Environment:windows10, .net46, .netCore
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Given an entity defined as such:
public class Foo
{
public ObjectId Id
public string Bar { get; set; }
}
I want the ability to "upsert" a document with an object having that type, where a new record would have an auto-generated "_id". After executing the following:
var foo = new Foo
{ Bar = "hello world" };
collection.ReplaceOne(x => x.Id.Equals(foo.Id), foo, new UpdateOptions
);
The mongo shell, however, reports the following:
> db.foo.find()
The _id inserted is equivalent to ObjectId.Empty. Even applying the [BsonIgnoreIfDefault] attribute atop the Id property has no effect.
Expected Behavior:
The .ReplaceOne() and .ReplaceOneAsync() methods would recognize that the Id has not been explicitly initialized and will "insert" with an auto-generated _id (when used in conjunction with the "upsert" flag) instead of performing, what it appears to be, an "update".