使用用户名和密码使用MONGO DB服务器检查连接

时间:2019-04-09 09:41:45

标签: mongodb authentication passwords connection

我想使用用户名和密码来连接到mongo服务器,这对我很有效---------

from pymongo import MongoClient

# MongoDB connection info
hostname = '10.20.30.40'
port = 27017
username = 'adminUserName'
password = 'secret'
databaseName = 'someDB'

# connect with authentication
client = MongoClient(hostname, port)
db = client[databaseName]
db.authenticate(username, password)
#It will show True if you are authenticated

0 个答案:

没有答案