Pymongo

1.查询数据

find:

find(filter=None,projection=None,skip=0,limit=0,no_cursor_timeout=False,
cursor_type=CursorType.NON_TAILABLE,sort=None, allow_partial_results=False, oplog_replay=False,modifiers=None, manipulate=True)
cursor = db.restaurants.find()
for document in cursor:
    print(document)
# 查询字段是最上层的
cursor = db.restaurants.find({"borough": "Manhattan"})
# 查询字段在内层嵌套中
cursor = db.restaurants.find({"address.zipcode": "10075"})
cursor = db.restaurants.find({"grades.score": {"$gt": 30}})
cursor = db.restaurants.find({"grades.score": {"$lt": 10}})
# AND
cursor = db.restaurants.find({"cuisine": "Italian", "address.zipcode": "10075"})
cursor = db.restaurants.find(
    {"$or": [{"cuisine": "Italian"}, {"address.zipcode": "10075"}]})

find_one

  find_one(filter_or_id=None, *args, **kwargs)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容