1、参考
https://www.cnblogs.com/gme5/p/11765151.html
https://blog.csdn.net/qq_43475458/article/details/107123220
https://blog.csdn.net/qq_41259576/article/details/107049604
用户权限参考
https://www.cnblogs.com/swordfall/p/10841418.html
dbAdmin权限满足基本需求
2、创建用户密码指定数据库
use test db.createUser({ user: "****", pwd: "****", roles: [{ role: "readWrite", db: "test" }] })
3、远程连接:代密码
import pymongo host = '***' username = ***' password = '***' port = *** conn = pymongo.MongoClient('mongodb://{}:{}@{}:{}/?authSource=test'.format(username,password,host,port)) db = conn.test # 直接写库名 coll = db['stu1'] coll.insert_one({"name":"zhangsan","age":18}) # 插入一条数据,如果没出错那么说明连接成功 for i in coll.find(): print(i)