localhost exception does not work for me

390 views
Skip to first unread message

Karrar mohammed

unread,
Dec 10, 2019, 2:26:41 PM12/10/19
to mongodb-user

I'm running mongod on virtual machine (vagrant) and inside the config file ,I've set the authorization to enabled

it is known that the mongod with security enabled(both authentication and authorization) can not authenticate the user since there are no users and here you can create the superuser ("root") on the admin db via connecting to the mongod via the localhost (localhost exception)

but after I connect to the server, when I want to create a root user on admin, an error message pops up saying

Error: couldn't add user: there are no users authenticated

by the way, the steps I followed are exactly the same as that in the course of cluster administration from MongoDB University

how to fix this?

Cahaba Data

unread,
Dec 10, 2019, 9:57:41 PM12/10/19
to mongodb-user
well even with auth enabled, the local user exception exists until the first user is created.... so the error message may just be due to an incorrect command...
one can use a command to create the first user from the vagrant prompt
or one can connect to mongo shell then
use Admin
and here put the create user

depending on where you launch your create user command the syntax differs somewhat but are very similar....
if you post an example it is perhaps just a syntax issue

Stennie

unread,
Dec 10, 2019, 10:53:49 PM12/10/19
to mongodb-user
Hi,

If the localhost exception isn't working for you, I would suspect one of the following scenarios:
  • you are not connecting via localhost from the VM's point of view (for example, using the private IP assigned via Vagrant/Virtualbox or connecting via port forwarding from the host machine)

  • you have previously created users on this deployment (which would disable the localhost exception)

  • your MongoDB configuration file has disabled the localhost exception by setting the enableLocalhostAuthBypass parameter to false.
The easiest fix for this would be to restart your MongoDB instance without access control enabled, create the desired admin user, and then restart your MongoDB with access control enabled.

If you want to try to troubleshoot why the localhost exception isn't working, please reply with some more details including your MongoDB server version and the specific mongo command line you are using to connect.

Regards,
Stennie 

Karrar mohammed

unread,
Dec 11, 2019, 11:29:51 AM12/11/19
to mongod...@googlegroups.com
I'm connecting to mongod like this 

mongo --host 127.0.0.1:28000

28000 is the port defined inside the config file

but how to connect via the localhost from the vm's point of view??

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/a2680fb1-02e6-4451-aeda-c7b61686cbe1%40googlegroups.com.

Karrar mohammed

unread,
Dec 11, 2019, 11:33:02 AM12/11/19
to mongod...@googlegroups.com
here is the config file 


storage:
  dbPath: "/var/mongodb/db"

systemLog:
  destination: file
  path: "/var/mongodb/db/mongod.log"
  logAppend: true

security:
  authorization: enabled

net:
  bindIp: "127.0.0.1,192.168.103.100"
  port: 28000

processManagement:
  fork: true

operationProfiling:
  mode: slowOp
  slowOpThresholdMs: 50

Matt Hughes

unread,
Dec 11, 2019, 8:40:40 PM12/11/19
to mongod...@googlegroups.com
I haven't used vagrant but in virtual box vm you would have to set the nic to bridged to be able to connect from outside of the vm

Cahaba Data

unread,
Dec 12, 2019, 8:13:22 PM12/12/19
to mongodb-user
your screen shot does not show if this mongod is part of replica set
if it is - then run the config of all nodes so they are all set up
log into 1 node i.e. mongo --port 28000
and then run
rs.initiate() 

then
use admin  to change to the admin db
then your create user code


On Wednesday, December 11, 2019 at 7:40:40 PM UTC-6, MH wrote:
I haven't used vagrant but in virtual box vm you would have to set the nic to bridged to be able to connect from outside of the vm

On Wed, Dec 11, 2019, 11:32 AM Karrar mohammed <k.moha...@gmail.com> wrote:
here is the config file 


storage:
  dbPath: "/var/mongodb/db"

systemLog:
  destination: file
  path: "/var/mongodb/db/mongod.log"
  logAppend: true

security:
  authorization: enabled

net:
  bindIp: "127.0.0.1,192.168.103.100"
  port: 28000

processManagement:
  fork: true

operationProfiling:
  mode: slowOp
  slowOpThresholdMs: 50

To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages