i need some help with my Mongo DB request.
This is my document structure:
{
"username" : "firstUser",
"email" : "[email protected]",
"subscriptions" : [
{
"subscriptionId" : ObjectId("59f972dfdaca9e39487e3bb4"),
"someOtherFields" : "otherValue",
"message" : {
"contact" : [
"[email protected]",
"[email protected]",
"[email protected]"
],
"subject" : "Mailsubject",
"content" : "Mailcontent"
}
},
{
"subscriptionId" : ObjectId("59faf26c8a593b25b8a9a8f7"),
"someOtherFields" : "otherValue",
"message" : {
"contact" : [
"[email protected]",
"[email protected]",
"[email protected]"
],
"subject" : "Mailsubject",
"content" : "Mailcontent"
}
}
}
Now i need to remove one E-Mail address from the subscriptions.message.contact array, where the subscriptions.subscriptionid = ObjectId("59f972dfdaca9e39487e3bb4").
I tried something like this:
db.getCollection('myCollection').update({
"subscriptions.subscriptionId" : ObjectId("59f972dfdaca9e39487e3bb4")
},
{
"$pull" : { "subscriptions": {"message.contact" : "[email protected]" }}
})
but it removed all subscriptions with this E-Mail address
Does anyone know, how to solve this problem?