I have a problem while upserting to mongo db using the official C# driver.
public abstract class AggregateRoot
{
///
/// All mongoDb docu
Looks like you might be explicitly setting the Id
value for both inserts and updates. That's fine for inserts, all new objects need an _id
value, however for updates you're not allowed to change the value of _id
on an existing document after it's created.
Try not setting the Id
value at all. If you don't specify a value before inserting, the driver uses built-in IdGenerator
classes to generate a new _id value, so if it's an ObjectId type it'll use the ObjectIdGenerator
. Then both your inserts and updates work fine.