我在mongoDB中有数据,如下所示
{
"_id": ObjectId("57c40e405e62b1f02c445ccc"),
"sharedPersonId": ObjectId("570dec75cf30bf4c09679deb"),
"notificationDetails": [
{
"userId": "57443657ee5b5ccc30c4e6f8",
"userName": "Kevin",
"isRed": true
}
]
}
现在我想将isRed
值更新为false
如何为此编写查询。我尝试了类似下面的内容
var updateIsRedField = function(db, callback) {
db.collection('notifications').update({_id:notificationId},
{
$set: { "notificationDetails.$": {isRed: false}},
}, function(err, results) {
callback();
});
};
MongoClient.connect(config.database, function(err, db) {
assert.equal(null, err);
updateIsRedField(db, function() {
db.close();
});
return res.json({});
});