Reputation: 4966
I'm trying to remove the field from the teacher array that contains a specific subject, such as "ok baby"
{
"_id" : "billy",
"password" : "$2a$10$MKZFNtMhts6rMbnIoqXB9.Q8NHAizQAGhX5S6g.8zeRt7TpRpuQea",
"teacher" : [
{
"subject" : "ok baby",
"students" : [
"billy"
]
},
{
"subject" : "adsfqewr",
"students" : [
"billy"
]
}
]
}
This is what I tried:
users.update( { 'teacher.subject':title, '_id':username},
{ $pull: { 'teacher.subject':title } },
{ multi: true }
)
Upvotes: 0
Views: 67
Reputation: 2014
The query should be like this .,,, pulling data from array is teacher and title is equal to title ...
users.update( { 'teacher.subject':title, '_id':username},
{ $pull: { 'teacher':{'subject':title}} },
{ multi: true }
);
Upvotes: 1