I found the behavior between Insert and Upsert is differenct when I use C# Driver v2.7. Something like this:
An entity such as:
// code placeholder public class Person { public ObjectID _id { get; set; } public string Name { get; set; } }
When I use Insert Method:
// code placeholder var collection = db.GetCollection<Person>(collectionName); Person entity = new Person(); entity.Name = "Peter"; collection.InsertOne(entity);
it's correctly stored in DB with generated ObjectId like this:
// code placeholder { "_id":"5bb67b8b8d3632037461b621", "Name":"Peter" }
But when I use Upsert such as:
// code placeholder ...... collection.ReplaceOne(item => false, entity, new UpdateOptions() { IsUpsert = true });
it's stored with default ObjectId (all zero) like:
// code placeholder { "_id":"000000000000000000000000", "Name":"Peter" }
Is it the reasonable behavior difference between Upsert and Insert ?