一 安裝模塊pymongomongodb
pip3 install pymongo
二 建立一個MongoClient數據庫
conn=MongoClient('mongodb://cbi:pass@ip1:20000,ip2:20000,ip3:20000')
三獲取數據庫spa
db=conn.testdb
四 獲取集合code
my_set = db.test
五獲取單個文檔blog
my_set.find_one()
my_set.find_one({"author": "Maxsu"}) #獲取匹配條件的單個文檔
六獲取全部文檔token
my_set.find() #返回一個cursor實例,能夠對其進行遍歷
for i in my_set.find(): print(type(i)) #裏面的文檔是字典類型 dict break