🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## **MongoDb使用记录** db.createUser( { user: "root",pwd: "123456", roles: [{role:"root",db:"admin"} ] } ) db.createUser({ user: "bjl", pwd: "123456", roles: [{ role: "userAdminAnyDatabase", db: "bjl" }] }); db.createUser({ user: "bjl6", pwd: "123456", roles: [{ role: "readWrite", db: "bjl6" }] }); db.createUser({ user: "bjl6", pwd: "123456", roles: [{ role: "readWrite", db: "bjl6" }] }); db.createUser({ user:'admin01',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]}); db.createUser({ user: "bjl5", pwd: "123456", roles: [{ role: "readWrite", db: "bjl5" }] }); db.createUser({ user: "bjl10", pwd: "123456", roles: [{ role: "readWrite", db: "bjl10" }] }); db.createUser({ user: "bjl11", pwd: "123456", roles: [{ role: "readWrite", db: "bjl11" }] }); db.createUser({ user: "dbj13", pwd: "123456", roles: [{ role: "readWrite", db: "dbj13" }] }); db.createCollection("log") db.createUser({ user: "bjl", pwd: "123456", roles: [{ role: "readWrite", db: "bjl" }] }); db.log.insert({"name":"meimei"}) show collections mongodb://dbj13:123456@lnmp_mongo:27017/dbj13 mongodb://dbj13:123456@lnmp_mongo:27017/dbj13 // 进入mongo命令行 mongo; // 切换到admin数据库 use admin; // 认证admin数据库; db.auth('root账号','root密码123456'); // 切换(创建)数据库 use bjl【指定数据库(没有数据库则创建)】 // 创建指定数据库的账号密码 db.createUser({ user: "bjl", pwd: "123456", roles: [{ role: "readWrite", db: "bjl" }] }); // 查询刚刚创建的数据库 show users; // 进入mongo命令行 mongo; // 切换到admin数据库 use admin; // 认证admin数据库; db.auth('root账号','root密码123456'); db.auth('root','123456'); // 切换(创建)数据库 use bjl【指定数据库(没有数据库则创建)】 use bjl6; // 创建指定数据库的账号密码 db.createUser({ user: "bjl6", pwd: "123456", roles: [{ role: "readWrite", db: "bjl6" }] }); // 查询刚刚创建的数据库 show users;