node.js - .findByIdAndRemove 不是函数
问题描述
考虑以下代码:
app.delete('/customer/:id',(req,res) =>{
var idRemove = String(req.params.id);
console.log(idRemove);//this part is working
var user = new Customers(req.body);
console.log(user)//this part is working
user.findByIdAndRemove({id :idRemove},(err, doc) => {
if (!err)
res.status(200).send(doc);
else {
res.status(500).send(err)
//showing error here telling me that user.findByIdAndRemove is not a function
}
})
});
我收到一条错误消息,上面写着“.findByIdAndRemove 不是函数”。
我怎样才能防止这个错误?
解决方案
在 mongoDB_id
中,为数据库中特定项目的 id保留关键字。我相信你应该改变 id
你的_id
代码。例如:
user.findByIdAndRemove({_id :idRemove},(err, doc) =>
推荐阅读
- javascript - 如何从Javascript中的集合数组中提取键的值
- java - 选择插入查询循环
- javascript - JS或Jquery中黄金价格的解析结果
- ffmpeg - 如何在背景图像上叠加视频?
- ansible - 迭代 Ansible 调试输出
- excel - 第一次迭代后循环文件夹中的所有文件失败
- docker - 使用 docker 构建时 Azure DevOps 私有 nuget 存储库未经授权
- webassembly - 为什么 0x83 0x00 格式良好的 3 编码为 Wasm 中的 u8?
- python - Conda 环境:打印已安装软件包的许可证
- python - 如何不打印 cmd 输出?