Mongo GridFS 发现投影问题

Mongo GridFS find with projection issue

我正尝试在 GridFS 中使用投影进行查询,如下所示:

Files = gridfs.GridFS(db)
f = Files.find({'metadata.AgentId': '1234'}, {'_id':1})

我收到了这个错误:

TypeError: skip must be an instance of int

因此,Cursor 的初始化程序将 {'_id':1} 作为第三个参数 >> 跳过。

另一方面,此查询在 Robo3T shell:

中运行良好

有什么想法吗?

Gridfs.find 方法中没有 projection 参数。

https://api.mongodb.com/python/current/api/gridfs/index.html#gridfs.GridFS.find https://github.com/mongodb/mongo-python-driver/blob/master/gridfs/grid_file.py#L796-L802

也许您应该使用 collection 的查找。 https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find

db['fs.files'].find({'metadata.AgentId': '1234'}, {'_id':1})