Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create user

I was using MongoDB version 2.6.6 on Google Compute Engine and used the click to deploy method.

rs0:SECONDARY> db.createUser({user:"admin", pwd:"secret_password", roles:[{role:"root", db:"admin"}]})
2015-07-13T15:02:28.434+0000 Error: couldn't add user: not master at src/mongo/shell/db.js:1004

rs0:SECONDARY> use admin
switched to db admin
rs0:SECONDARY> db.createUser({user:"admin", pwd:"secret_password", roles:["root"]})
2015-07-13T15:13:28.591+0000 Error: couldn't add user: not master at src/mongo/shell/db.js:1004
like image 443
Miguel Fermin Avatar asked Jul 13 '15 15:07

Miguel Fermin


People also ask

Can't create another user?

Step 1: Open the Run dialog using Win + R, then type control userpasswords2 and click OK to open the User Accounts dialog. Step 2: Select the Users tab, and then click the Add button. If the Add button is grayed out, check the "Users must enter a user name and password to use this computer" option.


1 Answers

I had a similar problem with mongo 3.2:

Error: couldn't add user: not master :

When trying to create a new user, with root role.

I was using only a local copy of mongo.

In my mongod.conf file I had the following uncommented:

replication:
   replSetName:  <node name>

Commenting that out and restarting fixed the problem. I guess mongo thought it was part of a replication set, and was confused as to who the Master was.

Edit:

I've also found that if you ARE trying to setup a replication set, and you get the above error, then run:

rs.initiate()

This will start a replication set, and set the current node as PRIMARY.

Exit, and then log back in and you should see:

PRIMARY>

Now create users as needed.

like image 78
comfytoday Avatar answered Sep 18 '22 15:09

comfytoday