MongoDB Manual / 参考 / 数据库命令 / 用户管理 定义 createUser 在运行命令的数据库上创建新用户。 如果用户存在,createUser命令将返回重复用户错误。 提示 在mongosh中,该命令也运行通过db.createUser()辅助方法运行。 辅助方法对mongosh用户来说很方便,但它们返回的信息级别可能与数据库命令不同。如果不追求方...
要在MongoDB部署中创建用户,请连接到部署,然后使用db.createUser()方法或createUser命令添加用户。 > use admin > db.createUser( { user:"root", pwd:"123456", roles:[{role:"root",db:"admin"}] } ) 1. 2. 3. 4. 5. 6. 7. 8. 修改密码 db.changeUserPassword("username","newpassword") ...
Create root user on MongoDB db.createUser( { user: "user", pwd: "pass", roles: [ "root" ] } ); use database; db.createUser( { user: "user", pwd: "pass", roles: [ { role: "readWrite", db: "database" } ] } );
db.createUser() returns a duplicate user error if the user already exists on the database. The db.createUser() method has the following syntax: Field Type Description user document The document with authentication and access information about the user to create. writeConcern document Optional. ...
Create Admin/Root User in MongoDB Switch toadmindatabase: > use admin Admin vs Root:The roleuserAdminAnyDatabasein MongoDB gives ability to create users and assign roles to them, but by itself it doesn’t allow the user to do anything else. The superuser role in MongoDB is theroot. ...
首先确保MongoDB服务已经启动,进入MongoDB的命令行,并且切换到admin数据库: > show dbs admin 0.000GB config 0.000GB local 0.000GB > use admin switched to db admin 1. 2. 3. 4. 5. 6. 添加权限为userAdminAnyDatabase的权限: db.createUser({ ...
MongoDB使用命令创建用户权错误分析 错误一:权限不够Error:couldn't add user:command createUser requires authentication、 解决方案:先使用超级管理员登录,再进行其他数据库用户创建的创建。
cd /usr/local/mongoDB/mongodbsoft/bin 执行命令 ./mongo 进入mongo use admin db.createUser( {user: "admin",pwd: "123456",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]}); 新创建管理员用户成功 管理员登录 db.auth('admin','123456') 管理员登录成功 6、改为--auth启动,并...
environment:-MONGO_INITDB_ROOT_USERNAME=user - MONGO_INITDB_ROOT_PASSWORD=password-MONGO_INITDB_DATABASE=test more explanation at:https://stackoverflow.com/a/42917632/1069610 This is how I do it, my requirement was to bring up a few containers along with mongodb, the other containers expect ...
将security.authorization值从enabled改为disabled 2.3 启动MongoDB /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.conf 3、验证 use admindb.createUser({user:"admin",pwd:"shenz2024",roles:[{role:"root",db:"admin"}]});