我想使用用户名和密码来连接到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