删除mongoose中包含在数组中的对象中的数组中的元素

时间:2018-05-02 12:48:45

标签: mongoose

我有像这样的mongoose这个属性的文档:

mapping: [
 { a: 1, b: [1,2,3] }, 
 { d: 1, c: [1,2,3] }
]

我的问题是,如何删除b中包含的值3。我有b值和数字' 3'。如果b为空,则删除整个对象{a: 1, b: [1,2,3]}

Test.findOneAndUpdate(
    { "mapping.a" : 1 }, 
    { "$pull": { "a.$.b": "3" } } 
)

我试试这个,但我需要b为空时删除对象。

0 个答案:

没有答案
相关问题