我想写一个函数在mongodb中返回mycollection
中包含的所有文档
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
最佳答案
这是从命令提示符运行时可以正常运行的示例代码。
from pymongo import MongoClient
if __name__ == '__main__':
client = MongoClient("localhost", 27017, maxPoolSize=50)
db = client.localhost
collection = db['chain']
cursor = collection.find({})
for document in cursor:
print(document)
请检查集合名称。
https://stackoverflow.com/questions/37941610/
相关文章:
node.js - MongoDB + nodejs : how to query ISODate
node.js - 从 node.js 连接到 mongodb 时出现 ECONNREFUSED 错
mongodb - 如何解决错误 :dbpath (/data/db/) does not exis
python - 如何关闭 mongodb python 连接?
mongodb - 在 mongo shell 中将 Mongo 查询输出打印到文件
node.js - nodejs mongodb对象ID到字符串