Loading

Python-Mongodb操作

1.链接mongodb

import pymongo

data_ip = "127.0.0.1"
data_port = "27017"
data_user = "root"
data_pass = "s123456"
client = pymongo.MongoClient(host=data_ip, port=int(data_port))
db = client.admin
db.authenticate(data_user, data_pass, mechanism='SCRAM-SHA-1')
db = client['cmdb']  #库名

#查询
mycol = db['cc_HostBase']  #集合名
mydoc = mycol.find_one() #查看第一行

print(mydoc)
posted @ 2022-01-07 09:06  日行一善g  阅读(17)  评论(0编辑  收藏  举报