node.js - Mongoose:updateMany() 没有按预期工作
问题描述
我正在使用猫鼬来处理我的数据库查询。我正在尝试完全使用此方法更新一组记录。模式代码如下所示:
// prepare database query
const filter = { type: 'company' };
const update = req.body.payload; // payload contains the array of objects (i.e. updated records)
const options = { new: true, runValidators: true }
// find and update the taxonomy record
await Taxonomy.updateMany(filter, update, options);
但是,每当我运行此查询时,我都会在控制台中收到以下错误:
Error [MongooseError]: Invalid update pipeline operator: "_id"
我想我的更新有效负载有问题。req.body.payload
看起来像这样:
[
{
_id: '5ef3d08c745428001d92f896',
type: 'company',
name: 'Company Size',
__v: 0
},
{
_id: '5ef3cdc5745428001d92f893',
type: 'company',
name: 'Company Industry',
__v: 0
}
]
你能告诉我这里到底出了什么问题吗?
解决方案
推荐阅读
- linux-kernel - 是否可以通过 RCU 保护 _____nf_conntrack_find() 返回值?
- javascript - 处理由 from() 创建的 observable 中的 promise 引发的错误
- react-native - 如何为 android 生成未签名的 apk - reac-native
- javascript - 当用户滚动回页面顶部时,如何使徽标效果恢复为“正常”?
- selenium - Appium - 无法获取子元素
- python - 有没有办法整合矩阵的每个条目并将解决方案作为另一个矩阵返回?
- android - 如何在我的 android 应用程序上共享来自 whatsapp 的图像和标题
- java - java.lang.IllegalStateException:API 响应后片段未附加到上下文
- reactjs - 使用 Reactjs 的列表中的列表
- angular - 在硬件后退按钮上检查是否存在任何模态并关闭模态