我想要一个集合中的所有文档编写一个函数来MongoDB中返回包含在mycollection
的所有文件获取使用Pymongo
from pymongo import MongoClient
if __name__ == '__main__':
client = MongoClient("localhost", 27017, maxPoolSize=50)
db=client.mydatabase
collection=db['mycollection']
cursor = collection.find({})
for document in cursor:
print(document)
然而,在函数返回:Process finished with exit code 0
你有没有花括号在查找方法尝试?尝试光标= db.mycollection.find() – YOBA
结果相同: 过程完成退出代码0 – MAYA
好吧,你怎么执行这个脚本? (还请调整缩进) – YOBA