可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When ever I try to connect to mongo db I always get this error as below.
MongoDB shell version: 2.4.3 connecting to: test Fri Apr 26 14:31:46.941 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112 exception: connect failed
I tried various solutions listed in stackoverflow and tried following commands but nothing works.
1) sudo rm /var/lib/mongodb/mongod.lock
// says such file located at this place.
2) sudo service mongodb start
// error: sudo: service: command not found
3) I've made sure nothing else is running at that port.
4) Even tried uninstalling and installing it again.
5) Also tried kill pid
回答1:
Same error here, this worked for me:
sudo mongod --repair
followed by
sudo mongod
(forget about service and start)
Then on a different tab/terminal:
mongo
回答2:
This is due to locking of Mongodb
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
回答3:
I had the same issue, In my case there was a mismatch of ipaddress in mongo config
~# mongo MongoDB shell version: 2.6.7 connecting to: test 2015-02-02T17:48:52.302+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2015-02-02T17:48:52.303+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146 exception: connect failed
When I checked my configuration file, I have specified the bind address to eth0 ip(10.8.10.111) not loopback address(127.0.0.1), So I have changed the ip address to loopback as like bind_ip = 127.0.0.1
in /etc/mongod.conf file and restart it with service mongod restart
, finally works
# mongo MongoDB shell version: 2.6.7 connecting to: test >
回答4:
Please Start the MongoDB server first and try to connect.
Pre-requisite:
Create space for storing DB and tables in any directory Example (windows): D:\mongodbdata\
Steps:
Start server
mongod --port 5000 --dbpath D:\mongodbdata\ (please mention above created path)
Connect mongodb server (Run in another terminal/console)
mongo --port 5000
回答5:
Faced same issue, my understanding is(it could be wrong)
1. Make sure mongodb is up and running
2. For linux access as sudo and for windows if connecting localhost turning off firewall may help but its not necessary
3. Just type mongo, it will try to connect to localhost by default. You need to specify IP if you are connecting to a remote server. By default test db will be used.
回答6:
mongod --configsvr --smallfiles --nojournal --dbpath cfg/1 --port 26052 --fork --logpath cfg/3.log >/dev/null
Create a single mongos server on the default port
sleep 2000 mongos --configdb ${HOSTNAME}:26050,${HOSTNAME}:26051,${HOSTNAME}:26052 --fork --logpath mongos.log >/dev/null
Sleep for some time before starting the mongos you will not face the problem
回答7:
If any one is facing the problem in windows machine then follow the steps.
- Add the path of mongodb in the environmental variable.
- Create a directory C:\Data\db.
- Open a terminal(cmd) and write mongod. (it will initiate the server).
- Open another terminal and write your own code.
回答8:
First start mongod
service then mongo
or mongos
回答9:
Start mongod server first
mongod
Open another terminal window
Start mongo shell
mongo
回答10:
If you create data\db
folder, firstly you must delete this folder then execute:
c:\mongodb\bin\mongo.exe
回答11:
Mongo DB requires space to store it files. So you should create folder structure for Mongo DB before starting the Mongodb server/client.
for e.g. MongoDb/Dbfiles where Mongo DB is installed.
Then in cmd promt exe mongod.exe and mongo.exe for client and done.
回答12:
I met with this problem too. And I figured it out by the following way:
First, open the terminal and write
mongod --dbpath {your project's path}
Second, open a new terminal and enter your project's path, write
mongo
Then it runs successfully
回答13:
with new version of mongodb, this issue got resolved.
回答14:
Quick Fix: I have the same problem to start the MongoDB and it was easily fixed by running the file mongod.exe
(C:\Program Files\MongoDB\Server\3.2\bin
) then run the file mongo.exe
(C:\Program Files\MongoDB\Server\3.2\bin
)..Problem fixed