备注:MongoDB进行全文检索的原理是进行分词搜索,对于中文而言是词语搜索,英文是单词搜索(如"李 明"和"李明"是两种不同的搜索结果),所以使用MongoDB进行中文全文检索效果不如英文好。
对指定字段关键词搜索:
client=pymongo.MongoClient('mongodb://username:pwd@ip_address:27017/')
db=client['db_']
collection=db['coll']
query={'title':{'$regex':'财政厅','$options':'i'}}
query_result=collection.find(query)
for i in query_result:
print(i)