I have a document collection like this:
{
"_id" : ObjectId("4fb21439f31dfd122ce39c4a"),
"Name" : "Freelander 2",
"Manufacture" : "Landrover"
}
I am using the C# driver, and want to check whether the “Name” field exists; if it does not, I need to update it from the code. Can someone help on this? Please share sample code because I am a newbie to mongoDB.
You can use the exists operator:
Using the C# driver, the equivalent would be something like this:
To set a value if it doesn’t exist, you can use an Update statement like this: