MongoDB running but can't connect using shell

前端 未结 17 1708
甜味超标
甜味超标 2020-12-23 16:45

CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)

MongoDB is running:

root     31664  1.5  1.4  81848 11148 ?        Sl   18:40   0:         


        
17条回答
  •  一整个雨季
    2020-12-23 17:09

    On Ubuntu:

    Wed Jan 27 10:21:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84 exception: connect failed

    Solution

    look for if mongodb is running by following command:

    ps -ef | grep mongo
    

    If mongo is not running you get:

     vimal     1806  1698  0 10:11 pts/0    00:00:00 grep --color=auto mongo
    

    You are seeing that the mongo daemon is not there.

    Then start it through configuration file(with root priev):

    root@vimal:/data# mongod --config /etc/mongodb.conf &
    [1] 2131
    root@vimal:/data# all output going to: /var/log/mongodb/mongodb.log
    

    you can see the other details:

    root@vimal:~# more /etc/mongodb.conf
    

    Open a new terminal to see the result of mongod --config /etc/mongodb.conf & then type mongo. It should be running or grep

    root@vimal:/data# ps -ef | grep mongo
    
    root      3153     1  2 11:39 ?        00:00:23 mongod --config /etc/mongodb.conf
    root      3772  3489  0 11:55 pts/1    00:00:00 grep --color=auto mongo 
    

    NOW

    root@vimal:/data# mongo
    
    MongoDB shell version: 2.0.4
    connecting to: test
    

    you get the mongoDB shell

    This is not the end of story. I will post the repair method so that it starts automatically every time, most development machine shutdowns every day and the VM must have mongo started automatically at next boot.

提交回复
热议问题