Node.js 在Express Mongoose中从数组中删除对象
我想删除id为608c530de8ade5221b0e6d4e的数组中的对象,这是我的代码,但这会导致错误 这是控制器:Node.js 在Express Mongoose中从数组中删除对象,node.js,typescript,express,mongoose,Node.js,Typescript,Express,Mongoose,我想删除id为608c530de8ade5221b0e6d4e的数组中的对象,这是我的代码,但这会导致错误 这是控制器: { "_id": "608c3d353f94ae40aff1dec4", "userId": "608425c08a3f8db8845bee84", "experiences": [ { "designation": &quo
{
"_id": "608c3d353f94ae40aff1dec4",
"userId": "608425c08a3f8db8845bee84",
"experiences": [
{
"designation": "Manager",
"_id": "609197056bd0ea09eee9429c"
},
{
"designation": "Asst. Manager",
"_id": "608c530de8ade5221b0e6d4e"
},
{
"designation": "Sr. Manager",
"_id": "608c534be8ade5221b0e6d4f"
},
]
}
这是一个模型:
const userId = req.userData.userId;
const id = req.params.id;
Experience.findOneAndUpdate({ userId: userId }, { $pull: { 'experiences': { '_id': id } }}, { multi:true }, function(err, obj) {
// //do something here
});
我在{$pull:{'experiences':{'u id':id}上遇到以下错误
错误:
没有与此调用匹配的重载。
过载1/3。。。。。。。。。
.......
预期的类型来自属性“$pull”,该属性在类型“UpdateQuery”上声明
你能试试这个吗:
No overload matches this call.
Overload 1 of 3 .........
.......
The expected type comes from property '$pull' which is declared here on type 'UpdateQuery<Document<any, {}>>'
这里有一个工作示例:哦,对不起,这些数字只是示例,实际的字符串就在那里。您能在工作示例中测试它吗?它能工作吗?没有重载与此调用匹配。在使用您的解决方案后,我得到了相同的错误。但它在我添加到问题的演示中起作用,并且我使用了来自您的问题的相同数据。你能把你的代码复制到问题上吗?我已经用真实的数据和代码更新了问题。请看一看
No overload matches this call.
Overload 1 of 3 .........
.......
The expected type comes from property '$pull' which is declared here on type 'UpdateQuery<Document<any, {}>>'
Folder.findOneAndUpdate({
"_id": "608c3d353f94ae40aff1dec4"
},
{
$pull: {
"experiences": {
"_id": "608c530de8ade5221b0e6d4e"
}
}
},
{
"multi": false
})