Unable to connect to MongoDB

前端 未结 9 1113
借酒劲吻你
借酒劲吻你 2021-02-02 11:17

I\'ve just installed MongoDB (standard Ubuntu build, not the latest stable) and for some reason I can\'t connect:

Mon Feb  6 03:11:22 Error: couldn\'t connect to         


        
相关标签:
9条回答
  • 2021-02-02 11:48

    By default, running the mongo console command will look for mongodb on your localhost, hence the 127.0.0.1 IP which is your local loopback. Also, the default config for mongod should be available on localhost. Its better to do it this way for now to start, unless you have turned on auth. Make sure you have auth enabled or your database is running openly on your public ip.

    When you want to connect to a host other than localhost or your default config, you do:

    mongo <host>
    
    0 讨论(0)
  • 2021-02-02 11:49

    Another way is to add mongod option param bind_ip

    mongod -–help
    

    --bind_ip arg comma separated list of ip addresses to listen on - localhost by default

    --bind_ip_all bind to all ip addresses

    mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db --bind_ip 0.0.0.0
    
    0 讨论(0)
  • 2021-02-02 11:53

    I had the same issue just because the silly mistake.

    first remove mongodb file which is fine

    rm -rf /tmp/mongodb-27017.sock
    

    where I did mistake inside the /etc/mongod.conf

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

    instead of

    net:
      port: 27017
      bindIp: 10.1.2.4
    

    for listen to all available ips

    bindIp: [127.0.0.1,10.128.0.2]
    

    restart the mongodb

    sudo service mongod start
    

    hopefully this answer help for someone

    0 讨论(0)
  • 2021-02-02 11:56

    following steps may help you :

    1. open terminal and run "sudo rm /var/lib/mongodb/mongod.lock"
    2. now run " sudo mongod --repair "
    3. now "sudo start mongodb"
    4. now just check the status of mongodb status "sudo status mongodb"

    5 lastly just invoke command "mongo"

    0 讨论(0)
  • 2021-02-02 12:05

    You must specify the IP (199.21.114.XX), by running mongo 199.21.114.XX.

    Otherwise, if you want it to listen on localhost as well, you should remove the bind_ip setting in your config file.

    Update Check your firewall config. Since you're connecting to the external IP, it can be configured to block, even from the local box.

    0 讨论(0)
  • 2021-02-02 12:05

    If you are using windows, run the services then check mongoDB server is running, if not running, Start it.

    mongoDB server by default run on localhost:27017. Click localhost:27017 the create an admin user first.

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