一.连接数据库
def connect(self):
while True:
client = pm.MongoClient("数据库地址", serverSelectionTimeoutMS=3)
try: client.admin.command("ping")
except (ConnectionError) as e:
return None
else:
break
return client
二.获取数据表
db = client.test #数据库
stb = db.users #用户表
三.查询
users= stb.find()
查询文档: http://www.runoob.com/mongodb/mongodb-query.html
四.遍历
for item in users:
print(item)