Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyMongo获取筛选器必须是dict的实例,bson.son.son错误_Python_Mongodb - Fatal编程技术网

Python PyMongo获取筛选器必须是dict的实例,bson.son.son错误

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" :

下面是我试图运行的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" : 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)