I am getting error creating new user in the database in Mongodb 3.4.2

438 views
Skip to first unread message

Shailesh Govani

unread,
Oct 22, 2017, 5:08:07 AM10/22/17
to mongodb-user
Having problem creating a user as shown .. below screenshot


[mongo@HQ-OMS10 db]$ /opt/mongodb/bin/mongo --host hq-oms10.pbfinvst.com
MongoDB shell version v3.4.2
connecting to: mongodb://hq-oms10.pbfinvst.com:27017/
MongoDB server version: 3.4.2
> use admin
switched to db admin
> db.createUser (
...    {
...      user: "appAdmin",
...      pwd: "password",
...      roles:
...        [
...          { role: "readWrite", db: "config" },
...          "clusterAdmin"
...        ]
...    }
... )
2017-10-20T15:04:32.809-0400 E QUERY    [thread1] Error: couldn't add user: not authorized on admin to execute command { createUser: "appAdmin", pwd: "xxx", roles: [ { role: "readWrite", db: "config" }, "clusterAdmin" ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 300000.0 } } :


------------- --------------------------------------------------------
Also can't check existing user(s) ... what to do ?
-----------------------------------------------------------------------

[mongo@HQ-OMS10 db]$ /opt/mongodb/bin/mongo --host hq-oms10.pbfinvst.com
MongoDB shell version v3.4.2
connecting to: mongodb://hq-oms10.pbfinvst.com:27017/
MongoDB server version: 3.4.2
> use admin
switched to db admin
> db.getUsers();
2017-10-20T15:52:37.787-0400 E QUERY    [thread1] Error: not authorized on admin to execute command { usersInfo: 1.0 } :
_
>

Kevin Adistambha

unread,
Oct 24, 2017, 8:26:49 PM10/24/17
to mongodb-user

Hi

The error:

Error: couldn’t add user: not authorized on admin to execute command

means that the current user you’re logged in as is not allowed to execute the createUser command.

However, since it appears that you did not provide any credentials when connecting to MongoDB, and it appears that the localhost exception is not active, it is likely that there is an existing user already defined in your deployment (otherwise the createUser command would succeed). Did you create this deployment yourself? If yes, did you follow the procedure outlined in https://docs.mongodb.com/manual/tutorial/enable-authentication/ ?

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages