my database has a structure like this:
{
"universe": "comics",
"saga": [
{
"name": "x-men",
"characters": [
{
"character": "wolverine",
"powers": [
{
"power": "self-recovery"
},
{
"power": "Super strength"
},
{
"power": "steels claws"
}
]
},
{
"character": "cyclops",
"powers": [
{
"power": "rays"
},
{
"power": "Super strength"
}
]
}
]
}
]
},
{
"universe": "comics",
"saga": [
{
"name": "spiderman",
"characters": [
{
"character": "venom",
"powers": [
{
"power": "Super strength"
}
]
}
]
}
]
}
I basically want to learn how to do operations with complex arrays, this time I think I will learn too much if I get the answer to this question.
I want to delete the objects where "power:"self-recovery"
something like $.saga.characters.$.powers
I don't know how to do it because of the number of levels this property is under the main root.
normally i would use something like that:
db.mydb.update(
{
saga: {
$elemMatch: { saga.characters.$ },
},
},
{ $pull: { powers: { power: "Super strength"
} }},
{
new: true,
multi:true
},
for this example it should delete as many objects where {" power ":" self-recovery"}
(in this case, only one object is deleted, which is where the character is wolverine
)
but i don't know how to do what i need.