I have an object in my mongodb collection. Its schema is:
{
"instruments": ["A", "B", "C"],
"_id": {
"$oid": "508510cd6461cc5f61000001"
}
}
My collection may have such object, but may not. I need to check if object with key "instruments" exists (please, notе, I don't know what value "instrument" is at this time, it may contain any value or an array), and if exists - perform update, otherwise – insert a new value. How can I do this?
collection.find( { "instruments" : { $exists : true } }, function(err, object){
if (object) {
//update
} else {
//insert
}
});
doesn't work ((