MongoDB not working. “ERROR: dbpath (/data/db) does not exist.”

前端 未结 5 956
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 12:07

I\'m getting the following error when I try to run \"mongod\" in the terminal. I\'ve tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to

相关标签:
5条回答
  • 2020-12-04 12:29

    Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:

    sudo systemctl enable mongodb    
    sudo systemctl start mongodb
    

    or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:

    sudo service mongodb enable
    sudo service mongodb start
    

    If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:

    rc-update add mongodb default 
    /etc/init.d/mongodb start 
    

    In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):

    • add the following line to /etc/rc.conf:

      mongod_enable="YES"

    • then:

      sudo service mongod start

    After starting the service, an unpriveleged user can use mongo, and each user will have separate data.

    0 讨论(0)
  • 2020-12-04 12:32

    This should work to ensure that the directory is set up in the right place so that Mongo can find it:

    sudo mkdir -p /data/db/

    sudo chown `id -u` /data/db

    0 讨论(0)
  • 2020-12-04 12:35

    I solved the problem with :

    sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.

    0 讨论(0)
  • 2020-12-04 12:35

    Change the user of the new data directory:

    chown mongodb [rute_directory]

    And try another time to start the mongo service

    service mongod start

    I solve the same problem with this.

    0 讨论(0)
  • 2020-12-04 12:47

    You need to create the directory on root /data/db or set any other path with the following command :

    mongod --dbpath /srv/mongodb/
    

    See the example link

    0 讨论(0)
提交回复
热议问题