0

I have a Document with this attribute in mongoose like that:

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

My question is, how can I delete the value 3 contained in b. I have b value and the number '3'. And if b is empty then delete the entire object {a: 1, b: [1,2,3]}

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

I try this but I need when b is empty delete the object.

recnac
  • 3,744
  • 6
  • 24
  • 46
CoffeAbuser
  • 446
  • 4
  • 7
  • 20

0 Answers0