Let's say I have this collection in MongoDB:
{
"_id" : ObjectId("5890e5ea619737392c257846"),
"email" : "ewrt@ert.com",
"pass" : "123456",
"firstName" : "sdlriugth",
"lastName" : "sdfligkjh",
"movies" : [
ObjectId("5890e5ec619737392c257847"),
ObjectId("5890e5ed619737392c257848"),
ObjectId("5890e5ee619737392c257849"),
ObjectId("5890e5ee619737392c25784a")
]
}
{
"_id" : ObjectId("5890e5f8619737392c25784c"),
"email" : "wieruy@dgf.com",
"pass" : "123456",
"firstName" : "yjhtgj",
"lastName" : "vbnvbng",
"movies" : [
ObjectId("5890e5fa619737392c25784d"),
ObjectId("5890e5fb619737392c25784e"),
ObjectId("5890e5fc619737392c25784f")
]
}
There are 2 users, each user has an array of movies id's.
I want to do a query that will remove a specific movie Id from the user that has this movie.
let's say if I'll remove the movie id : "5890e5ee619737392c25784a" I will get:
{
"_id" : ObjectId("5890e5ea619737392c257846"),
"email" : "ewrt@ert.com",
"pass" : "123456",
"firstName" : "sdlriugth",
"lastName" : "sdfligkjh",
"movies" : [
ObjectId("5890e5ec619737392c257847"),
ObjectId("5890e5ed619737392c257848"),
ObjectId("5890e5ee619737392c257849"),
]
}
{
"_id" : ObjectId("5890e5f8619737392c25784c"),
"email" : "wieruy@dgf.com",
"pass" : "123456",
"firstName" : "yjhtgj",
"lastName" : "vbnvbng",
"movies" : [
ObjectId("5890e5fa619737392c25784d"),
ObjectId("5890e5fb619737392c25784e"),
ObjectId("5890e5fc619737392c25784f")
]
}
P.S I what the changes to be made on all relevant documents. (many users can have the same movie id)
Thanks :)