Not able to add the user after starting primary replication node

This one is interesting. I have written all the config files and I have the first instance of the replication set up and running. I have set it to primary by running rs.initiate() and I have verified that it is the primary by running rs.status().

When I use the db.createUser and enter the admin user, I get the following:

"Error: couldn’t add user: net authorized on test to execute command {createUser: “m103-admin”, pwd: “xxx”, roles: [{role: “root”, db: “admin”}], digestPassword: false, writeConcern… and a whole lot of jibberish after that. I’ll post the actual output below.

2018-10-26T07:52:54.958+0000 E QUERY [thread1] Error: couldn’t add user: not authorized on test to execute command { createUser: “m103-admin”, pwd: “xxx”, roles: [ { role: “root”, db: “admin” } ], digestPassword: false, writeConcern: { w: “majority”, wtimeout: 600000.0 }, $clusterTime: { clusterTime: Timestamp(1540540299, 1), signature: { hash: BinData(0, 073DAC60233B7D9ECB15C03A769569EC1DD772B3), keyId: 6616569472230621186 } }, $db: “test” } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1

Recommendations???

Just got it. Make sure you use admin database before inserting the user.

Hi David_44057,

I believe the problem is solved. You need to use admin database first to run the db.createUser command.

use admin
db.createUser()

Also, after creating a user, and with authentication enabled, you will always have to authenticate mongodb with the user first.

Kanika

1 Like