pymongo user password to connect

# db mongodb
db_mongo_attr = {
'host': '*',
'port': 27,
'database':'tease',
'username':'*v',
'password':'*
}

def db_conn(*args):
"""
:return:pymongodb db级别的实例
"""
dbs = pymongo.MongoClient(di['host'],
di['port'],)
#dbs = pymongo.MongoClient("mongodb://user:pass@ip/database")
db = dbs[di['database']]
db.authenticate(di['username'],di['password'])
return db


db = db_conn ()
Note that the user is mongodb integrated with the database, it is verified user permissions at the database level.

 

Guess you like

Origin www.cnblogs.com/wodeboke-y/p/10991968.html