简体   繁体   中英

MongoDB command createUser requires authentication

I just installed Mongo DB on my Linux Server. Now I want to create an main admin user. I followed the offical docs, but every time I run the command I get:

uncaught exception: Error: couldn't add user: command createUser requires authentication: _getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype.createUser@src/mongo/shell/db.js:1386:11 @(shell):1:1

I really don't know what I should do to fix this error. Inside the /etc/mongod.conf config file authentication is disabled:

security:
    authorization: "disabled"

Thanks for help!

To create the first user, you need to have authentication enabled and use the localhost passthrough: open mongoshell (the mongo command) from the same server in which the database is running.

Note that the passthrough is valid only when you connect via localhost and when no users have yet been created (once you create the first user, you will need to authenticate to perform any tasks). If you already created a user but don't remember the password, you will need to delete the entire dbPath folder, restart mongod and then use the passthrough to create the first user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM