我试图从包含特定主题的教师数组中删除该字段,例如"ok baby"
{
"_id" : "billy",
"password" : "$2a$10$MKZFNtMhts6rMbnIoqXB9.Q8NHAizQAGhX5S6g.8zeRt7TpRpuQea",
"teacher" : [
{
"subject" : "ok baby",
"students" : [
"billy"
]
},
{
"subject" : "adsfqewr",
"students" : [
"billy"
]
}
]
}
这就是我的尝试:
users.update( { 'teacher.subject':title, '_id':username},
{ $pull: { 'teacher.subject':title } },
{ multi: true }
)
答案 0 :(得分:1)
查询应该是这样的。,,,从数组中提取数据是老师,标题等于标题......
users.update( { 'teacher.subject':title, '_id':username},
{ $pull: { 'teacher':{'subject':title}} },
{ multi: true }
);