添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
胡子拉碴的豆腐  ·  Mongoose URI is ...·  1 月前    · 
逆袭的鸭蛋  ·  Delete Documents - ...·  1 月前    · 
多情的仙人球  ·  [Answered] How does ...·  1 周前    · 
礼貌的稀饭  ·  ⚙️ Customize Spring ...·  1 周前    · 
奋斗的木瓜  ·  Create DBRefs in MongoDB·  1 周前    · 
打酱油的手套  ·  后街女孩_百度百科·  10 月前    · 
重感情的番茄  ·  【Bug】Failed to write ...·  1 年前    · 
风流倜傥的单杠  ·  XR Plugin Management ...·  1 年前    · 

I’m working on a server setup tutorial, but the error below is not resolved, so I’m asking a question.

When I try to create a user with db.createUser in the mongo shell, I keep getting an error like the one below.

> use admin;
switched to db admin
> db.createUser({user: "test", pwd: "test", roles:["root"]});
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

In the config, security is commented out like this:
# security:
# authorization: enabled

I’m using AWS EC2 instance which uses Ubuntu Server 18.04

Thanks!

Seeing that the auth error appears even when listing users, there seems to be a problem with auth, but I don’t know how to solve it.

> show users;
uncaught exception: Error: command usersInfo requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1659:15
shellHelper.show@src/mongo/shell/utils.js:914:9
shellHelper@src/mongo/shell/utils.js:819:15
@(shellhelp2):1:1

Hi @111860 ,

Is the shell run on the same host as this process? How do you connect?

Have you restarted the server after commenting security section?

It seems that security is stilll enabled

Thanks
Pavel

After commenting security section, I restarted mongod and it worked fine!

The problem was that I didn’t restart the server.

Thank you so much. Actually, I almost quit studying programming after trying to solve this all day by myself. But actually it was no big deal…

Thank you so much and I hope you have a nice day!

111860:

Seeing that the auth error appears even when listing users, there seems to be a problem with auth, but I don’t know how to solve it.

Welcome to the MongoDB Community Forums @111860!

If you enabled access control without creating any users, there is a Localhost Exception that allows you to login via localhost in order to create the first admin user (after which, the exception will no longer be available).

Alternatively you can restart mongod without enabling access control in order to create the first user, but that is a riskier approach I would not recommended. If you take the latter approach, don’t forget to restart your mongod with access control enabled after creating your initial admin user.

Regards,
Stennie