I have an application which makes Upserts into a MongoDB database, using the c# driver for MongoDB. When I call the Update function, I can't specify the type I want to update, and then a _t field is inserted with the type of the element.
Here's the code I use to upsert:
collection.Update(
    Query.EQ("key", item.Key),
    Update.Replace(item),
    UpdateFlags.Upsert
);
Here's the result:

This does not happen when I do the initial inserts, since I can specify the type.
How can I make Upserts without inserting the _t field?
[Edit] That's the code I use for inserting:
collection.InsertBatch(ItemType, items);
                You can pass the ItemType in the Update.Replace method:
collection.Update(
    Query.EQ("key", item.Key),
    Update.Replace(ItemType, item),
    UpdateFlags.Upsert
);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With