Datemodel = {
"_id": "5922f58599ff690ea4ffb4cd",
"events": [
{
"eventDate": "2017-04-30T18:30:00.000Z",
"eventName": "Project Name",
"_id": "591e953982c0423238721b09"
},
{
"eventDate": "2017-05-15T18:30:00.000Z",
"eventName": "Project Name",
"_id": "591e953982c0423238721b08"
},
{
"eventDate": "2017-05-29T18:30:00.000Z",
"eventName": "Project Name",
"_id": "591e953982c0423238721b07"
}
]
}
我想更新eventName的值,其event._ID是591e953982c0423238721b09
我已执行以下查询
router.route('/postPhase')
.post(function (req, res) {
var eventID = req.body.eventID
var eventName = req.body.eventName
var query = {
events._id: eventID
}
dataModal.findOneAndUpdate(query,{$set:{events.$.eventName:"eventName"}},{"new":true},function(err, Data){
res.json(data)
})
})
请帮我把数据更新到数据库中