我想要一個集合中的所有文檔編寫一個函數來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