use admin
db.createUser({
user:"admin",
pwd:"abc123456",
roles:[{role:"root",db:"admin"}]
})
开启权限认证 在 C:\Program Files\MongoDB\Server\4.0 目录下新建 mongodb.cof
dbpath=C:\Program Files\MongoDB\Server\4.0\data
logpath=C:\Program Files\MongoDB\Server\4.0\log\mongod.log
auth=true
mongod --config "C:\Program Files\MongoDB\Server\4.0\mongo.cnf" --reinstall
重启服务
登录
mongo --host localhost --port 27017
db.auth("admin","abc123456")