I want to find any document in my collection that:
- its hobby field is empty
- or its hobby field doesn't exist
and then set the value of its hobby field to be equivalent of its sports field.
db.myCollection.update(
{ $or: [{"hobby": {$exists: false} },{"hobby": ""}]}
, {
$set: {
hobby: ????sports
}
}, {
multi: true
},
function(err, result) {
console.log(result);
console.log(err);
})
With this command above, I suppose I will be passing the value of sports as fixed value to all matching documents. is there any way to pick up its corresponding sports value and set it to hobby?