切换到要加密的数据库
use diary
创建有 readWrite
权限的用户
db.createUser({ user: "youuser", pwd: "youpassword", roles: [{ role: "readWrite", db: "diary" }] })
启用权限验证
./mongod --auth
命令行连接
./mongo -u "youuser" -p "youpassword" --authenticationDatabase diary
url连接
mongodb://youuser:youpassword@localhost:27017/diary