[英]How to update array of embedded collection field based on another collection embedded field value in MongoDB?
[英]How to update mongodb collection and embedded array
我知道这已经被问了数百次......但我找不到任何适合我的东西。
我的查询... PUT `http://localhost:8000/api/question/60ccc5031dfd8b1da15f83af
身体...
{
"position": "1",
"question": "If a clerk gave me a shower cap",
"left": "southpaw"
}
My code ...
await Question.findByIdAndUpdate(
{ "_id": req.params.id },
{ $set: {updates, answers} },
{ new: true }, (err, result) => {
if (err) {
res.send(err);
}
res.send(result);
})})
Nothing is changed in the database. Please help me figure out what I'm doing wrong
不知道发生了什么,但这有效......
const updated = await Question.findByIdAndUpdate(
{ "_id": req.params.id },
{ $set: updates, options},
{ new: true}
)
if (!updated) {
return next(new ErrorResponse(`Question not found with id of ${req.params.id}`), 404)
}
res.json(updated)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.