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