Lab- Launching mongod : Can't add user

I have successfully launched the mongod process with port 27000 and the given ip, but can’t add the user. Need help!

vagrant@m103:~$ mongo --port 27000
MongoDB shell version v3.6.14
connecting to: mongodb://127.0.0.1:27000/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“361d0703-7b02-43e2-acce-a59456ab9e28”) }
MongoDB server version: 3.6.14
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser({user: “m103-admin”, pwd: “m103-pass”, roles: [{role: “root”, db: “admin”}]})
2019-08-30T08:34:39.543+0000 E QUERY [thread1] Error: couldn’t add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1

Hi @Dibyendu_79103,

Can you please confirm if this is a standalone mongod or a replica set?
Also, kindly share the command you are using to launch your mongod.

Thanks,
Muskan
Curriculum Support Engineer

1 Like

Hi,

Am facing the same error. Maybe i might have created the same user initially in the first place, however am unable to check the same as well , as show dbs is also giving me unauthorized access issues.

Try to authenticate the user

use admin
db.auth(“m103-admin”,“m103-pass”)
If it returns 1, that means user is already there
You can check users with db.getUsers()

1 Like

I ran into the same issue today:

“Error: couldn’t add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15”

Started mongod with no auth, and still ran into the same issue! Which isn’t correct. So i launched a new terminal to ssh into m103, and then tried (still no auth); and user creation was successful.

Launched mongod with auth.
Launched new terminal to ssh into m103 >> this time user was created successfully.

unable to start mongod. getting error:

about to fork child process, waiting until server is ready for connections.
forked process: 2604
ERROR: child process failed, exited with error number 1

Please paste the command you ran
Do you have mongod.log.
Try to run without fork
Most likely your dir is missing or you issued command from a different directory or some permission issue

I face a similar problem and error-message as Dibyendu_79103 but could not solve the problem by re-running as did tandav_49291.

Last login: Sun Sep 22 13:37:03 2019 from 10.0.2.2
vagrant@m103:~$ mongo admin --host localhost:27000 --eval ’

db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

MongoDB shell version v3.6.14
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“acf2c15f-d089-4143-94f7-6f14181641c8”) }
MongoDB server version: 3.6.14
2019-09-22T13:39:08.956+0000 E QUERY [thread1] Error: couldn’t add user: there are no users aut
henticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell eval):2:1

started server with below command…
mongod --dbpath /data/db --logpath /data/logs --bind_ip ‘127.0.0.1,192.168.103.100’ --fork

this comand says not able to connect to [ but simply doing mongo connects]
mongo admin --host localhost:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

can any please share what exact config params requried to start mongod

i tried not luck
mongod --dbpath /data/db --logpath /data/logs --bind_ip ‘127.0.0.1,192.168.103.100’ --fork
do i also need keyFile ??

Hi @brij2804,

As @Ramachandra_37567 mentioned, please share the details of your log file or run the mongod instance without the –fork option.

And also please make sure that the port on which you are trying to run your mongod instance is not being used by any other instance.

If this is the case, then you can either use a different port to run the current mongod instance or kill any other mongod instance which is using that specific port and start the current instance.

You can use the the command mentioned below to kill all the mongod instances running on your system.

killall mongod

If you have any other issue, please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi @Tilman_66516,

Did you run your mongod instance with –replSet option ?

If so then you need to remove this parameter and the corresponding value because this converts your standalone node into a replica set with a single node. This single node runs as a secondary node which does not have write permissions and hence you are not able to create the user.

You need to remove the –replSet option when you are running the mongod instance and you should be able to create the user.

If the issue still persists please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi @arun2pratap,

No, for this lab you don’t need the keyFile.

I would advise you to do these things :

  1. The command that you have shared, you have not specified any log file in here. For instance it could be –logpath /data/logs/mongod.log

After making this change if you are still not able to run the mongod instance then do this.

  1. Run the mongod instance without the –fork option and then share the output with us so that we can better understand the problem.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

sir trying to run this command but getting the following error in logFile (ps no instances are running in the background)
vagrant@m103:~$ mongod --port 27000 --bind_ip “192.168.100.103,127.0.0.1” --dbpath data/db/ --logpath data/log/mongod.log --fork

vagrant@m103:~$ cat data/log/mongod.log
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] MongoDB starting : pid=3175 port=27000 dbpath=/home/vagrant/data/db/ 64-bit host=m103
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] db version v3.6.14
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] git version: cbef87692475857c7ee6e764c8f5104b39c342a1
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] modules: enterprise
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] build environment:
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] distarch: x86_64
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] options: { net: { bindIp: “192.168.100.103,127.0.0.1”, port: 27000 }, processManagement: { fork: true }, storage: { dbPath: “data/db/” }, systemLog: { destination: “file”, path: “data/log/mongod.log” } }
2019-09-23T06:20:15.231+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] now exiting
2019-09-23T06:20:15.231+0000 I CONTROL [initandlisten] shutting down with code:48

Hi @AkshatTewari23012001,

Please change the IP address in the above command to 192.168.103.100 and it should work fine.

However, if the issue still persists, please feel free to get back to us.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Dear Shubham Ranjan,

thanks for your reply.

No, I did not run mongod with the -replSet option.

I opened the vagrant in one window, submitting the following command:

mongod --dbpath /data/db/ --port 27000 --bind_ip “127.0.0.1,192.168.103.100” --auth

as this leaves my window blocked (since I did not use a --fork flag), I then opened a second window/console with vagrant$m103 exectuing the code provided by you “mongo admin …”

I am still getting the same error-message as the one I have sent befor.

Kind regards, Tilman

Hi @Tilman_66516,

I think you might already have created the user. Can you please start your mongod instance using the command mentioned below.

mongod --dbpath /data/db/ --port 27000  --bind_ip "127.0.0.1,192.168.103.100" --auth

If everything went well, you should see this message at the bottom.

waiting for connections on port 27000

17%20PM

Now connect to your mongod instance using this command.

mongo --port 27000 -u m103-admin -p m103-pass

Once connected please, try to run this command :

show dbs

If everything went well you should be able to see the list of the databases.

I hope it helps. Please feel free to get back to us, if the issue still persists.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi Shubham ,

Facinf this issue not sure why when everything is right.

Hi @ANSHUL_65600,

It must be a temporary issue. If the issue is still not resolved then I would suggest you to kill the mongod process and then restart it and run the validator.

Hope it helps!

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi,

I am having the same problem as [ANSHUL_65600] after running exactly same instructions.

In spite of killing mongod process and restarting it and running validation script again, I keep getting the same error message:

Client experienced a timeout when connecting to the database - check that mongod

is running on the correct port, and that the ‘m103-application-user’ user

authenticates against the admin database.