【发布时间】:2020-03-19 20:49:43
【问题描述】:
我的 MongoDB 文档如下所示:
{_id: ObjectId("xxx"),
username: 'user',
active_courses: [
{'name': 'MongoDB',
'notes': [
{'title': 'Note title',
'note': 'Actual note content'}
]}
]
现在我需要更新带有标题“注释标题”的注释对象。我该怎么做?
我尝试了以下方法,但它不起作用。
Student.findOneAndUpdate(
{username:req.body.username},
{$set: {'active_courses.$[course].notes.$[note]': req.body}},
{arrayFilters: [{'course.name': req.body.course},{'note.title': req.body.title} ]})
.then(result => {
res.status(200).json({message: 'Note saved!'})
})
顺便说一句,我不知道数组的索引,所以我不能使用 active_courses[0].notes...
感谢有关此问题的任何帮助。谢谢!
【问题讨论】:
标签: node.js mongodb mongoose document