1. find() 函数, 可以在函数体内直接指定 filter, sort, projection(限制field), 语法如下:
datas = col.find(
filter = {"$and":[{"_id":{"$gte":datetime.datetime(2017, 1, 20)}}, {"_id":{"$lte":datetime.datetime(2017, 1, 20, 7, 15, 30, 0)}}]},
sort = [("_id", pymongo.ASCENDING)],
projection = {"_id":1, "lastPrice":1})
也可以写成下面的样子:
datas = col.find( {"$and":[{"_id":{"$gte":datetime.datetime(2017, 1, 20)}}, {"_id":{"$lte":datetime.datetime(2017, 1, 20, 7, 15, 30, 0)}}]}, {"lastPrice":1, "_id":1}).sort("_id", pymongo.ASCENDING)
api: http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find
时间: 2024-10-18 12:00:36