skip to Main Content

I am not sure what I need to do. Every time I try to run the mongo shell on Linux I get an error asking me to stop the database before running MongoDB with start-noauth. I am not sure how to do that. Can you help me out?

I have tried to stop and exit MongoDB but the issue still exists.

2

Answers


  1. if you dont want shutdown the "usually way":

    systemctl stop mongod
    or
    service stop mongod
    

    you can stop like this:

    # enter in the mongodb
    mongo
    # change to admin database
    use admin
    # shutdown the database
    db.shutdownServer()
    
    Login or Signup to reply.
  2. In general it does not look very smart if you want to restart your MongoDB without authentication when authentication is actually enabled. Usually there is a reason to have authentication enabled.

    The proper way would be to stop the MongoDB

    systemctl stop mongod
    

    and then disable authentication in your configuration file, typically at /etc/mongod.conf:

    security:
      authorization: disabled 
    

    Then you can restart the service with

    systemctl start mongod
    

    If you don’t know the location of the config file, check the service file:

    $ systemctl status mongod
    ● mongod.service - MongoDB Database Server
       Loaded: loaded (/etc/systemd/system/mongod.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2023-02-16 14:29:12 CET; 1 months 15 days ago
    
    
    $ cat /etc/systemd/system/mongod.service
    [Unit]
    Description=MongoDB Database Server
    Documentation=https://docs.mongodb.org/manual
    After=network.target
    
    [Service]
    User=mongod
    Group=mongod
    Environment="OPTIONS=-f /etc/mongod.conf"
    ExecStart=/usr/bin/mongod $OPTIONS
    ...
    

    Above commands apply for Redhat/CentOS Linux, they may differ on your Linux.

    But as said, usually it is a good habit to enable authentication and I would assume there was a reason to enable it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search