Javascript 如何从mongoose上另一个数组内的数组中删除项目
我需要从另一个数组中的数组中删除一个对象 异步函数removeEp(id、sectionindex、productindex){ 设t=wait Stores.findById(id); t、 截面[sectionindex].eps.splice(productindex,1); 等待t.保存(); 返回t; } 我尝试了这段代码,但它并没有改变数据库中的任何内容请考虑在保存之前调用Javascript 如何从mongoose上另一个数组内的数组中删除项目,javascript,arrays,mongodb,mongoose,remove,Javascript,Arrays,Mongodb,Mongoose,Remove,我需要从另一个数组中的数组中删除一个对象 异步函数removeEp(id、sectionindex、productindex){ 设t=wait Stores.findById(id); t、 截面[sectionindex].eps.splice(productindex,1); 等待t.保存(); 返回t; } 我尝试了这段代码,但它并没有改变数据库中的任何内容请考虑在保存之前调用部分 异步函数removeEp(id、sectionindex、productindex){ 设t=wait
部分
异步函数removeEp(id、sectionindex、productindex){
设t=wait Stores.findById(id);
t、 截面[sectionindex].eps.splice(productindex,1);
t、 markModified('sections');//添加此行
等待t.保存();
返回t;
}
也许可以尝试使用
await Stores.findOneAndUpdate({ _id: t._id }, { sections: t.sections });
而不是
await t.save();
欢迎使用Stack Overflow,回答并查看问题,请使用示例文档或架构更新您的问题,并获得预期结果。@turivishal它可以正常工作,但不保存