C# Question

How to insert and update documents info into mongodb?

I am kind of newbie in MongoDB.
I have a list of documents. Some of them are already in database.
I need to insert or update data in Mongo using C#.
What is the best method to do it?

Thanks for answers.

Answer Source

The easiest way would be to use the upsert option in the update command

     upsert: <boolean>,
     multi: <boolean>,
     writeConcern: <document>

So in C# something like

    Query.EQ("someproperty", propertyValue),

The above command replaces the ENTIRE document so use with caution. You can also use the <update> part of the command to update individual fields like this

var update = Builders<BsonDocument>.Update.Set("someProperty", newValue);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download