如果我想读取我的数据数据库(mongoDB)的所有集合,我使用find()“print”方法(学院查找数据库())“我们出错了
错误:
“Database”对象不可调用。如果要对“MongoClient”对象调用“find”方法,则会失败,因为不存在此类方法。在
如何修复?
代码源:from pymongo import MongoClient
from pymongo import *
import os
import pprint
mongodb_host = 'localhost'
mongo_port = '27017'
client = MongoClient(mongodb_host + ':'+mongo_port)
db = client['test']
cl=db.client
try:
pprint.pprint(cl.find())
except Exception as e:
print ('this connection or insert are wrong.')
print (e)
错误:'Database' object is not callable. If you meant to call the 'find'
method on a 'MongoClient' object it is failing because no such method
exists.
如何修复它?