python中對Mongodb進行find操作


查找全部:

db.collectionName.find()
根據字段查找(精確匹配,大小寫敏感):
db.collectionName.find( { "cuisine": "Italian"} )
或的關系:
db.restaurants.find({ $or: [ { "cuisine": "Italian" }, { "address.zipcode": "10075" } ] })
AND關系:
db.restaurants.find({ "cuisine": "Italian", "address.zipcode": "10075" })
排序:
db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )
正則表達式:
# 1.包含:
db.collectionname.find({'files':{'$regex':'File'}})
# 2.開頭,結尾:
db.collectionname.find({'files':{'$regex':'^File$'}})
# 3.忽略大小寫:
db.collectionname.find({'files':{'$regex':'^file','$options':'i'}})
# 或者是:
import re
regx = re.compile("^name", re.IGNORECASE)
db.collectionname.find_one({"files": regx})

 

轉載自:https://blog.csdn.net/zhangruixia0108/article/details/49836829


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM