Fork me on GitHub

mongoDB 入门

mongoDB 入门

快速参考文档ReferenceCards-PDF


from pymongo import MongoClient

client = MongoClient()
db = client.test

# queries for all documents in the restaurants collection
cursor = db.restaurants.find()

条件查询 Specify Equality Conditions

{ <field1>: <value1>, <field2>: <value2>, ... }

https://docs.mongodb.org/manual/core/document/#document-dot-notation

Query by a Top Level Field

cursor = db.restaurants.find({"borough": "Manhattan"})

Query by a Field in an Embedded Document

cursor = db.restaurants.find({"address.zipcode": "10075"})

Query by a Field in an Array
following queries for documents whose grades array contains an embedded document with a field grade equal to "B".

cursor = db.restaurants.find({"grades.grade": "B"})

条件查询 Specify Conditions with Operators

{ <field1>: { <operator1>: <value1> } }

https://docs.mongodb.org/manual/reference/operator/query/

posted @ 2016-02-24 15:42  weaming  阅读(311)  评论(0编辑  收藏  举报
 |  Github |  知乎 |  微博  |