Python PyMongo获取筛选器必须是dict的实例,bson.son.son错误
下面是我试图运行的python代码。但是,我得到一个错误,它说Python PyMongo获取筛选器必须是dict的实例,bson.son.son错误,python,mongodb,Python,Mongodb,下面是我试图运行的python代码。但是,我得到一个错误,它说 TypeError: filter must be an instance of dict, bson.son.SON, or any other type that inherits from collections.Mapping query = db.collections.table.find({ "$and": [ { "time": { "$gte" :
TypeError: filter must be an instance of dict, bson.son.SON, or any other type that inherits from collections.Mapping
query = db.collections.table.find({ "$and": [ { "time": { "$gte" : 5000 } }, { "time" : { "$lte": 10000 } }, { "blt_id":20} ] })
projection = db.collections.table.find({ "alt_id": 1, "time": 1, "__id": 0})
for doc in db.collections.table.find(query, projection):
print(doc)
如何解决此问题?
query
和projection
应该是dict
s;通过一些优化,您的代码应该是:
query = {"time": {"$gte": 5000, "$lte": 10000}, "blt_id": 20}
projection = {"alt_id": 1, "time": 1, "_id": 0}
for doc in db.collections.table.find(query, projection):
print(doc)