pymongo篇---查询数据表中最新一条记录和多条件查询
一:查询数据表中最新一条记录
import pymongo
client = pymongo.MongoClient('localhost', 27017)
baseName = client['waste_bag_sum']
table_name = "waste_bag_2022-01-04"
tableName = baseName[table_name]
results = tableName.find().sort('_id', -1).limit(1)
results = [x for x in results]
print(results)
二:多条件查询
def findById(tableName, cameraID, tag):
results = tableName.find({'cameraID': cameraID, 'tag': tag}).sort('_id', pymongo.DESCENDING).limit(1)
results = [x for x in results]
return results