Reputation: 55273
I'm getting the following error:
alex@alex-K43U:/$ mongo
MongoDB shell version: 2.2.0
connecting to: test
Thu Oct 11 11:46:53 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
alex@alex-K43U:/$
This is what happens when I try to start mongodb:
* Starting database mongodb [fail]
I already tried mongo --repair
I made chown and chmod to var, lib, and data/db and log mongodb.
Not sure what else to do. Any suggestions?
mongodb.log:
***** SERVER RESTARTED *****
Thu Oct 11 08:29:40
Thu Oct 11 08:29:40 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 08:29:40
Thu Oct 11 08:29:41 [initandlisten] MongoDB starting : pid=1052 port=27017 dbpath=/var/lib/mongodb 32-bit host=alex-K43U
Thu Oct 11 08:29:41 [initandlisten]
Thu Oct 11 08:29:41 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 08:29:41 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 08:29:41 [initandlisten] ** with --journal, the limit is lower
Thu Oct 11 08:29:41 [initandlisten]
Thu Oct 11 08:29:41 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 08:29:41 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 08:29:41 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 08:29:41 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Thu Oct 11 08:29:41 [initandlisten] Unable to check for journal files due to: boost::filesystem::basic_directory_iterator constructor: No such file or directory: "/var/lib/mongodb/journal"
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Thu Oct 11 08:29:41 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Thu Oct 11 08:29:41 dbexit:
Thu Oct 11 08:29:41 [initandlisten] shutdown: going to close listening sockets...
Thu Oct 11 08:29:41 [initandlisten] shutdown: going to flush diaglog...
Thu Oct 11 08:29:41 [initandlisten] shutdown: going to close sockets...
Thu Oct 11 08:29:41 [initandlisten] shutdown: waiting for fs preallocator...
Thu Oct 11 08:29:41 [initandlisten] shutdown: closing all files...
Thu Oct 11 08:29:41 [initandlisten] closeAllFiles() finished
Thu Oct 11 08:29:41 dbexit: really exiting now
EDIT:
I removed the lock then did mongod repair and got this error:
Thu Oct 11 12:05:37 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
so I did it with sudo:
alex@alex-K43U:~$ sudo mongod --repair
Thu Oct 11 12:05:42
Thu Oct 11 12:05:42 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 12:05:42
Thu Oct 11 12:05:42 [initandlisten] MongoDB starting : pid=5129 port=27017 dbpath=/data/db/ 32-bit host=alex-K43U
Thu Oct 11 12:05:42 [initandlisten]
Thu Oct 11 12:05:42 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 12:05:42 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 12:05:42 [initandlisten] ** with --journal, the limit is lower
Thu Oct 11 12:05:42 [initandlisten]
Thu Oct 11 12:05:42 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 12:05:42 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 12:05:42 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 12:05:42 [initandlisten] options: { repair: true }
Thu Oct 11 12:05:42 [initandlisten] Unable to check for journal files due to: boost::filesystem::basic_directory_iterator constructor: No such file or directory: "/data/db/journal"
Thu Oct 11 12:05:42 [initandlisten] finished checking dbs
Thu Oct 11 12:05:42 dbexit:
Thu Oct 11 12:05:42 [initandlisten] shutdown: going to close listening sockets...
Thu Oct 11 12:05:42 [initandlisten] shutdown: going to flush diaglog...
Thu Oct 11 12:05:42 [initandlisten] shutdown: going to close sockets...
Thu Oct 11 12:05:42 [initandlisten] shutdown: waiting for fs preallocator...
Thu Oct 11 12:05:42 [initandlisten] shutdown: closing all files...
Thu Oct 11 12:05:42 [initandlisten] closeAllFiles() finished
Thu Oct 11 12:05:42 [initandlisten] shutdown: removing fs lock...
Thu Oct 11 12:05:42 dbexit: really exiting now
But still having the same problem.
Upvotes: 182
Views: 547309
Reputation: 51
First try:
sudo service mongod restart
If you get the error:
Active: failed (Result: exit-code) since Mon 2021-03-29 19:59:07 WEST; 3s
This may occur because the permission setting on /var/lib/mongodb
and /tmp/mongodb-27017.lock
are wrong. You will have to change the owner to monogdb user
Try:
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo service mongod restart
Upvotes: 5
Reputation: 369
Err : Couldn't connect to server 127.0.0.1:27017
This is solution for WINDOWS users
Create directory:
mkdir c:\mongo\data\db
Install service: first go to your bin directory in programs files of MongoDB with cd
mongod.exe --install --logpath
Start MongoDB:
net start MongoDB
4.Start Mongo Shell:
`c:\mongo\bin\mongo.exe` or
go to until bin and enter mongo
Note : Open terminal in Administrator mode
Upvotes: 0
Reputation: 68
One possible thing that may cause this error is your MongoDb Server process/service is not running.Check whether it's running, if not then You can try starting the MongoDb Server service from task manager also as shown in below snapshot.
Upvotes: 0
Reputation: 165
I had my mongod service masked, I had to use this command to remove it.
sudo systemctl unmask mongod
then restart the service
Upvotes: 0
Reputation: 778
In Windows run cmd
as Admin:
1.Create Directory:
mkdir c:\mongo\data\db
2.Install Service:
mongod.exe --install --logpath c:\mongo\logs --logappend --bind_ip 127.0.0.1 --dbpath c:\mongo\data\db --directoryperdb
3.Start MongoDB:
net start MongoDB
4.Start Mongo Shell:
c:\mongo\bin\mongo.exe
This solution worked for me.
Upvotes: 6
Reputation: 489
This work's for me. On Linix Ubuntu 20
Upvotes: 0
Reputation: 824
In local database mongo Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
try using this command
mongod --config /usr/local/etc/mongod.conf --fork
Upvotes: 0
Reputation: 1048
MAC OS
if you have mac and useing mongodb4.4, you can run:
brew services start [email protected]
Upvotes: 10
Reputation: 352
Sample solution Press Window+R and type services.msc to view all the services on machine Then find MongoDBServer right click it and start it. Then go to C:\Program Files\MongoDB\Server\4.2\bin and type mongo on command promt.
Upvotes: 0
Reputation: 11455
Ubuntu 18.04LTS: The problem arises when I uninstalled my previous version completely and installed 4.2.6
After hr's of googling, I solved another problem
MongoDB Failing to Start - ***aborting after fassert() failure
I was hopeless about the problem couldn't connect to server, because everything seems ok.
Finally, I decided to restart the operating system and guess what... BINGO
sudo mongo // works like a charm
Upvotes: -1
Reputation: 1377
If you are using OS X systems, there is no service
commands. So you won't be able to execure sudo service mongod start
.
Check this answer https://unix.stackexchange.com/a/155746 for more help!
Upvotes: 0
Reputation: 328
I got a similar error but the root cause was different. After installing the mongodb using homebrew. https://docs.mongodb.com/manual/installation/ I have to start the "mongod" service before giving the "mongo" command on terminal.
Upvotes: 0
Reputation: 1326
This it's because the mongod process it's down, you must to run the commands bellow in order to get up the mongod process:
~$ sudo service mongodb stop
~$ sudo rm /var/lib/mongodb/mongod.lock
~$ sudo mongod --repair --dbpath /var/lib/mongodb
~$ sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
~$ sudo service mongodb start
Hope this helps you.
Upvotes: 85
Reputation: 5264
simple Run Two commends
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
Upvotes: 0
Reputation: 994
In the terminal run these commands
1)
$ sudo service mongod start
2)
$ mongo
Upvotes: 3
Reputation: 16297
Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
sudo mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
Step 4: Check status of mongodb.
sudo status mongodb
or
sudo service mongodb status
Step 5: Start mongo console.
mongo
Upvotes: 175
Reputation: 465
This Works for me To stop the mongodb use:
use admin
db.shutdownServer()
And to Restart:
sudo service mongod restart
Upvotes: 1
Reputation: 307
Just run mongod --repair
from C:\Program Files\MongoDB\Server\4.0\bin
Here is the doc https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/
Upvotes: 0
Reputation: 72
1.Create new folder in d drive D:/data/db
2.Open terminal on D:/data/db
3.Type mongod and enter.
4.Type mongo and enter.
and your mongodb has strated............
Upvotes: 0
Reputation: 2641
For future reference,Follow these steps to avoid similar errors:
1.Download MondoDB https://www.mongodb.com/
2.Open a terminal and cd into your downloads folder or whatever folder youve saved your mondodb download(Ensure you extract your mongodb folder before you cd into it)
cd Downloads
3.Move mongodb to your usr/local path
sudo mv mongodb-osx-... /usr/local/mongodb
4.cd into your local folder
cd /usr/local/mongodb
5.make a new directory
sudo mkdir -p /data/db
6.cd into the new directory just created above
cd /data/db
7.give mongo permisions
sudo chown YourMacUserName /data/db
8.Then go/open your .bash_profile
To do so,follow these steps:
In your a new terminal
1.cd
2.pwd
3.ls -l
Check if the .bash_profile appears on your list of files on your terminal
if not create the -bash_profile
Creating .bash_profile:
In your terminal
touch .bash_profile
//skip this step if you already have a .bash_profile
Step8:
Next in your terminal:
open .bash_profile
And in your bash file that pops open add the following:
MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
And then save.(File Save or command S/CMD+S)
Step9:back in your terminal:
source .bash_profile
Now open two terminals.One will for your mondo daemon the other for your mongo.
Terminal 1: in your terminal type:mongod
mongodb
Terminal 2:
mongo
Also make sure you dont make the following typo error when starting your mongod in your terminal: This is incorrect
mongo d
gives off the following error: Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
This is Correct:
mongod
(There should be no space between the words mongo and d..mondod
Finally always keep in mind that you have to run mondod before you run mongo on your terminals.
Upvotes: 4
Reputation: 31
type windows+r and enter the following
services.msc
start MongoDB
now type "mongo" in cmd in the respective path where the mongo.exe is present, it will start working.
Upvotes: 0
Reputation: 384
Adding the bin to PATH in Environment Variables helped.
GOTO Installation Path and copy the ../bin to the PATH variables in environment variables in Windows
Upvotes: 0
Reputation: 31237
Although the answers are received, I would wish to discuss about network errors in MongoDB
.
Setting the safe write concerns is not the full proof method to make sure that we're safe. Let's assume that w=1
& j=true
are set, what if the write acknowledgement didn't received from the server? Well, the likelyhood is it didn't happened, but it might have happened. The reason why this might have happened is that there are network errors - there are reasons that we may not receive an affirmative response. So, we can send the request from the application through a driver of language of choice. mongod
can complete it successfully and then there could be a TCP reset, and the network actually can get reset in a way that we never receive response. So, we could get an error and on the error, we might assume that we got an error. It didn't happened, but it may happen.
For an insert, it's possible to guard against it. It's possible because if we let the driver create the _id
and we do an insert - then we could do that insert multiple times and it would be any harm. Because, if we do this 1st time and we get an error and we're not sure whether or not that insert completed because it's a network error, then we could just do it again. And provided we perform it again, tyr to perform it with the exact _id
. The worst case scenario is we'll get a duplicate key error when we try to insert it.
However, an update is where the problem occurs. Especially, the update which is not item potent, that for instance included a $ink
command. So, we're telling the database to increment a certain field. Well in that case, if we get a network error and we don't know whether or not the update occurred. Now, maybe we know enough about the values that we can check with them that the update occurred, which is fine. But if we don't know the starting value in the database for that field, then it's not possible for us to know whether or not it occurred or not in case of network error. This kind of issues are extremely rare with a fine network.
And if we really need to avoid it at all costs, what we need to do is turn on all our updates into inserts, by reading the full value of the document out of the database and then potentially deleting it and inserting it again or just inserting a new one.
The reasons why an application may receive an error back even if the write was successful:
MongoDB
server terminates between receiving the write and responding to it.Upvotes: 1
Reputation: 2886
I have mongo version 3.2.1 and had to delete the lock file from /data/db/
and after this, ran mongod
and it started successfully.
>rm /data/db/mongod.lock
>mongod
Upvotes: 2
Reputation: 1430
so first you have to remove the mongod.lock file by below command
sudo rm /var/lib/mongodb/mongod.lock
and then restart the mongo service by issuing below command
sudo service mongod restart
Upvotes: 7
Reputation: 2842
This error could be caused by the MongoDB's bind IP setting. You can check MongoDB's config file by
$ sudo vi /etc/mongodb.conf
In my case, the bind IP is set to server's intranet address, just as following:
bind_ip = 10.10.1.14
#port = 27017
So I have give mongo an IP parameter to connect to shell by type:
$ mongo 10.10.1.14
Don't forget to restart mongodb service if you changed the config.
Upvotes: 2
Reputation: 20110
After removing mongod.lock which was inside the data directory in my windows OS,it was still showing the same error message. I had to run mongod with --dbpath to make the mongo command run without errors.
Upvotes: 1
Reputation: 735
After frequent attempt finally I got to troubleshoot the problem...
Step 1: ps aux | grep mongo
Step 2: sudo rm /var/lib/mongodb/mongod.lock
Step 3: sudo mongod --repair
Step 4: mongo
Upvotes: 2