简体   繁体   中英

pymongo/mongodb: query if an element in an array of mongodb object

If I would like to query if a field in an array I can do this

students.find({'name':{$in:['Mark','Jerry']}})

But what if I would like to find a string is in a array of an mongodb object like

{
  "name":"Jerry",
  "classes":["math","english","nature"]
}

How do I query if a class name "science" in classes array of this mongodb object?

Thanks

只是:

db.students.find({'classes': 'science'})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM