1. 程式人生 > >python中mongodb的list查詢

python中mongodb的list查詢

這裡topic_question中的topic_list是一個數組,需要查詢topic_list中匹配給定兩個元素的條目

listf=list()
results = db.topic_questions.find({'$and': [{'topic_list':source}, {'topic_list': target}]})
for result in results:
    listf.append({'question': result['title'], 'answers_count': result['answers_count']})

參考連結:

https://stackoverflow.com/questions/18148166/find-document-with-array-that-contains-a-specific-value

http://www.runoob.com/python3/python-mongodb-query-document.html

https://stackoverflow.com/questions/10018730/how-use-sql-like-in-pymongo

https://blog.csdn.net/LanSeTianKong12/article/details/51725453