Home > Mobile >  Unable to connect to MongoDB when security Authentication is Enabled
Unable to connect to MongoDB when security Authentication is Enabled

Time:08-11

I have installed MongoDb on a Raspberry Pi to set it up as a DB server. I followed the instruction on the mongodb website to install it on the pi. I was able to successfully install and connect to it using the pi as well as an external computer over the network.

As I followed the instructions to make it more secure, I created a new user and I uncommented these lines

#security:
#authorization: enabled

in the /etc/mongod.conf file and restarted the service. This change does not let me connect to the mongodb.

I have tried using these commands to connect:

mongo
mongo localhost -u username -p password
mongo localhost -u "username" -p "password"

Also tried adding --port 27017 to all the above commands. Is there something I am missing? Here is my mongodb config file:

  GNU nano 5.4                                                                                                   /etc/mongod.conf                                                                                                             
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
  #bindIp: 0.0.0.0

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

CodePudding user response:

The configuration file is YAML format, you must use spaces:

security:
  authorization: enabled

And restart the mongod

  • Related