您的位置:首页 > 数据库 > Mongodb

python mongodb 查找find()

2015-11-14 16:58 375 查看
查找全部:
db.collectionName.find()
根据字段查找(精确匹配,大小写敏感):
db.[code]collectionName
.find( { "cuisine": "Italian"} )[/code]
或的关系:
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})

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: