从对象数组中删除特定的嵌套对象 [英] Remove a specific nested object from an array of objects
本文介绍了从对象数组中删除特定的嵌套对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要删除嵌套在对象数组中的特定对象.
I need to remove a specific object that is nested inside an array of objects.
下面的数据库结构看起来像:
The following db structure looks like:
我想根据 roomId(以查找特定房间)和团队 已批准 状态删除其中一个团队.如果团队已批准:错误",则需要将其从对象数组中删除.
I would like to remove one of the teams based on the roomId (to find the specific room) and based on the team approved state. If a team has "approved: false" it needs to be deleted from the array of objects.
我正在使用猫鼬并想出了以下内容,但没有成功:
I'm using mongoose and came up with the following, but without succes:
Room.update({"roomId": req.params.roomId},
{"$pull": { "teams.approved": false } })
显示正确 roomId 的屏幕截图:
screenshot thats shows the correct roomId:
推荐答案
应该像 这个例子,试试:
await Room.update({"roomId": req.params.roomId}, {"$pull": { "teams": { approved: false } } })
这篇关于从对象数组中删除特定的嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文