from bson.objectid import ObjectId |
import pymongo |
#查询代码 |
#连接本机mongodb |
conn = pymongo.Connection() |
#指定数据库 |
db = conn.books |
#指定collection |
collection = db.book |
#大于 |
collection.find({ '_id' :{ '$gt' :ObjectId( '51f6126139ecbb1db4a75667' )}}) |
#大于等于 |
collection.find({ '_id' :{ '$gte' :ObjectId( '51f6126139ecbb1db4a75667' )}}) |
#小于 |
collection.find({ '_id' :{ '$lt' :ObjectId( '51f6126139ecbb1db4a75667' )}}) |
#小于等于 |
collection.find({ '_id' :{ '$lte' :ObjectId( '51f6126139ecbb1db4a75667' )}}) |