0

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 }
)
Squirrl
  • 4,909
  • 9
  • 47
  • 85

1 Answers1

1

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 }
 );
Muhammad Ali
  • 1,992
  • 1
  • 13
  • 20