node.js - 猫鼬 findOneAndUpdate 不从数组中删除对象
问题描述
我遇到了猫鼬“findOneAndUpdate”查询的问题。以下是我的文档的架构结构。
{
"_id": "5fe2b6145dcd48c505000590",
"email": "user1@mail.com",
"todos": [
{
"_id": "5fe2b990fb9d7055c46d83a4",
"text": "important task",
"status": "in-progress"
}
]
}
我试图通过该特定对象的email
和从对象的“待办事项”数组中删除待办事项对象。_id
以下是我正在使用的代码。
let { task_id, email } = req.body
UserModel.findOneAndUpdate({ email : email},
{
$pull : {
todos : {
_id : task_id
}
}
},
{ safe: true, new: true },
function(err, model) {
if(err){
return res.send(err)
}
return res.send(model)
}
)
上面的代码只是返回预设文档,而不是从todos
数组中删除对象。
上面的代码有什么问题?
解决方案
推荐阅读
- java - 看不到客户服务 - Backoffice Migration Hybris
- layout - 在 SAPUI5 中设计布局
- twilio - Twilio 状态回调 url (webhook) 是同步的还是异步的
- python - 有什么方法可以读取 .docx 文件,包括使用 python-docx 自动编号
- python - 如何在 DBSCAN 中将包含分类数据和连续数据的数据集放入用户定义的度量函数中?
- c# - 嵌入 UserControl 的 Grid.Row 值的数据绑定不会更新 GUI
- sql - 从表中获取与列完全匹配的记录
- html - 无法在 SVG 中显示度数字符 (°)
- javascript - Visual Studio 不为 ASP.Net 的班级成员提供建议
- firebase - Firebase 安全规则仅读取特定项目