MongoDB won't start after server crash - mongodb

My Ubuntu computer had crashed, and when I restarted it MongoDB wasn't working. I tried the following commands, and got the following output:
$ mongo
Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
$ service mongodb status
mongodb stop/waiting
$ service mongodb restart
stop: Unknown instance:
start: Rejected send message, 1 matched rules; type="method_call",
sender=":1.57" (uid=1000 pid=2227 comm="start mongodb ")
interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)"
requested_reply="0"
destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
$ tail /var/log/mongodb/mongodb.log
[initandlisten] exception in initAndListen: 12596 old lock file, terminating
dbexit:
[initandlisten] shutdown: going to close listening sockets...
[initandlisten] shutdown: going to flush diaglog...
[initandlisten] shutdown: going to close sockets...
[initandlisten] shutdown: waiting for fs preallocator...
[initandlisten] shutdown: closing all files...
[initandlisten] closeAllFiles() finished
dbexit: really exiting now
(Output reformatted to match website layout.)
What happened? How can I fix it?

The log file is telling you that you have an "old lock file". MongoDB keeps a lock file while it's running. It creates this file when it is started, and deletes it when it's stopped. When the computer crashes (or MongoDB crashes, e.g. via kill), this file is not deleted, and thus the database does not start. The existence of this file indicates unclean shutdown of MongoDB.
Two things can be done:
If this is a development machine and you haven't been using your database (and neither have your programs), you can remove the file manually. For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock. For other versions, the file could be in a different path or it could be named mongo.lock.
The safer route is to follow MongoDB's Durability and Repair guide. In summary, for a machine with the above configuration, you should execute the following commands:
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
sudo service mongod start

all I had to do was run:
sudo mongod --repair
then:
sudo mongod

Based on my experience, I usually delete the "mongod.lock" file that is inside the database folder - In my case:
*I browse to where the database is installed on my ubuntu i.e. "data" folder.(cd data); list the files (ls)
*Then, I will remove the "mongod.lock" file that was automatically created when the database crashed, by issuing "rm mongod.lock" file.
After which I will either issue "./mongod" to start the mongo deamon or mongo to start the mongo shell. And everything will be fine.

Check to see if you have enough free space on your server. If there is no room left mongodb won't start.

If you did not use monitoring tools like Bluepill or Monit etc you will have to face this issue because after server crash due to some reason mongo didnot start its daemon automatically then you have to make it work manually, like sudo service mongod restart
I figured this issue but it needs some more tasks to be done, please make sure your dbpath at /etc/mongod.conf before starting your mongo daemon.
For me it was
storage:
dbPath: /var/lib/mongodb
When i enter mongod command it shows me MongoDB starting : pid=10795 port=27017 dbpath=/data/db 64-bit host=xyz.com make sure your dbpath is as same as mentioned in /etc/mongod.conf
To do this you can type sudo mongod --dbpath /var/lib/mongodb and then use mongod command to start your mongo process at your desired dbpath.
FYI: start your mongo process with mongod command

This is probably not the best solution, but if you're desperate you can try this. It seemed that only the journal was a problem for me, so I took these steps:
Create a new data directory. Possibly /var/lib/mongodb2
Update your mongod.conf to point to the new data dir.
Start mongoDB.
If it starts successfully, then you can shut down mongo again and proceed, otherwise you can stop reading here.
Locate your previous data dir and copy the files for your database(s) to your new data directory (example, admin.0 admin.1 admin.ns, etc)
Start mongoDB again (still using the new data directory)
After completing these steps (took less than 5 min), I was up and running and all data appeared to be ok.

Thank's guys. We also faced an issue where MongoDB was restarting over and over again an it was complaining about old lock file. I stopped MongoDB from Windows service list and then I deleted the mongod.lock file. After that I was able to start MongoDB service correctly and it worked fine.

Removing .lock file from mongo data directory dbpath works for me.
e.g sudo sudo rm {data-directory}/mongod.lock

Related

Error with mongodb on mac permission denied

Hi I have problem when I run
mongod
This is what I got
2016-02-09T21:54:40.631-0700 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-02-09T21:54:40.633-0700 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-02-09T21:54:40.633-0700 I CONTROL [initandlisten] dbexit: rc: 100
I try everything uninstall mongo. Install with brew. Uninstall with brew etc. Change the permission of my data folder and get always the same problem.
So this is what I did. I delete the /data/db folder after a recreate it with
sudo mkdir -p /data/db
Change the permission of data and db folder
mongod
everything working. My error was I didn't change the permission before I run mongod for the first time now everything is working fine.
I was having the same issues until I ran
sudo chown -R 'youruserid' /data/db
it seems some file(s) in the directory still had the wrong permissions.
I think I had a similar problem with my mongo install in my Mac. Have you tried changing the owner of /db/data?
You can check who owns this directory (where the databases are stored) by writing the following command in the terminal.
ls -al /data/db
If the owner (the name in the third column) is not your user, change it with a chown command or try running mongod with sudo.
I would first check to see if you have another instance of mongo running as it suggests. If you do not - remove the lock file in question and try to launch mongo again. It is possible the lock file is a remnant of a previous install.
systemctl enable mongod.service
Start mongod service at system startup
service mongod start

'Failed to unlink socket file" error in MongoDB 3.0

I am new to MongoDB. I am trying to install MongoDb 3.0 on Ubuntu 13.0 LTS, which is a VM on Windows 7 Host. I have installed MongoDB successfully (packages etc.), but when I execute the command sudo service mongod start, I get the following error in the "/var/log/mongodb/mongod.log" log file. Can anyone help me understanding this error. There is nothing on internet related to this.
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED *****
2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-04-23T00:12:00.931-0400 I - [initandlisten] Fatal Assertion 28578
2015-04-23T00:12:00.931-0400 I - [initandlisten]
I have fixed this issue myself, by deleting the mongodb-27017.sock file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock is now
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock
Alternative to the answer provided by KurioZ7, you can simply set the permissions of the .sock file to the current user:
sudo chown `whoami` /tmp/mongodb-27017.sock
This does the trick for me if I want to run mongod without sudo. If I delete the file like in KurioZ7s answer, I will simply get the same error the next time I restart my machine.
This issue occurs when you use the command
mongod
Before using the command
sudo service mongod start
To fix the issue, either:
Set appropriate permissions on the file:
/tmp/mongodb-27017.sock
OR
Remove the file
/tmp/mongodb-27017.sock
Run
sudo service mongod start && mongod
The most likely cause for this was that the mongod process was at some point started by the root user. The socket file (/tmp/mongodb-27017.sock) was therefore owned by the root user. The mongod process usually runs under its own dedicated user, and that user did not have the permissions to delete that file.
The solution, as you already found out, was to delete it. Then mongodb was able to recreate it with the correct permissions. This should persist after reboot, as long as mongodb is started using the init scripts, or under the correct user account.
$ sudo mongod
it solve problem for me
Change the ownership mongodb-27017.sock file in /tmp directory and start the mongod again.
cd /tmp
sudo chown mongodb:mongodb mongodb-27017.sock
sudo systemctl start mongod
For UNIX-based operating systems, as an alternative to the answer provided by Bastronaut, you could also specify the .sock file to be saved to a folder over which mongod has full user rights (corresponding to the way you are running mongod), that way mongod will also be able to remove the .sock file upon shutdown. The default folder to which the .sock file is saved is '/tmp'. To specify another folder, use a custom mongodb configuration file, for instance 'mongodb.conf', and add the following to it:
net:
unixDomainSocket:
pathPrefix: "anotherFolder"
After which you can run mongod with the command:
$ mongod --config /path/to/mongodb.conf
You can read the documentation on: https://docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
Manually restarting mongod service after restart fixed the problem.
Long-term solution was to add static host name, instead of ip address 'net' part of mongod.conf file (I suspect the problem is that ip address is not yet given to server, when mongod servis starts).
If you are having this problem using docker, refer to this question:
MongoDB docker container “Failed to unlink socket file”

MongoDB can not start after restart the system on Ubuntu 14.04 LTS

I've installed mongoDB on ubuntu 14.04 according to the official installation guide: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
I enter the terminal using "mongod" and everything is OK.
But when I shut down my ubuntu and restart it, command 'mongod' just cannot start, one error happens below:
2015-01-30T15:47:51.582-0800 [initandlisten] allocator: tcmalloc
2015-01-30T15:47:51.582-0800 [initandlisten] options: {}
2015-01-30T15:47:51.583-0800 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
After that, I tried to create the folder and chmod it using:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
but another error happened:
2015-01-30T16:01:43.855-0800 [initandlisten] allocator: tcmalloc
2015-01-30T16:01:43.855-0800 [initandlisten] options: {}
2015-01-30T16:01:43.859-0800 [initandlisten] journal dir=/data/db/journal
2015-01-30T16:01:43.859-0800 [initandlisten] recover : no journal files present, no recovery needed
2015-01-30T16:01:43.994-0800 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2015-01-30T16:01:43.994-0800 [initandlisten] ERROR: addr already in use
2015-01-30T16:01:43.994-0800 [initandlisten] allocating new ns file /data/db/local.ns, filling with zeroes...
2015-01-30T16:01:44.197-0800 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
I also looked for /etc/mongod.conf,
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongod.log
logappend=true
#port = 27017
where I found the default data storage folder is not /data/db
I've tried other ways like
sudo service mongod stop
sudo service mongod restart
But they simply do not work.
May be there's another instance already run when the system starts, but how can I stop it?
ERROR: addr already in use indeed means that you have another instance already running.
Did you try to:
type mongo in the terminal and see if it connects to the server?
check the logs in /var/log/mongodb/mongod.log? Do they tell you an instance is up?
type ps -edf | grep mongod and see if any process is running? I suppose it's not a good practice but did you try to kill it if one shows up, and type mongod again?
Aynway, you may want to try two things:
When you type sudo service mongod stop and before the sudo service mongod restart, try to type mongod in the terminal. As you normally stopped the running instance, you should be able to start your own
You could try to start another instance. For that, you will have to specify at least the port (and chose a different one than the default one), and preferably the dbpath (make sure to chose a path to a directory that already exists). You can do that on the command line, for example:
$ mongod --port 28000 --dbpath /path/to/your/db
Or you can create your own mongodb.conf, based on the default one, change the values for port and dbpath, and start mongod specifying the path to this config file:
$ mongod -f /path/to/your/mongod.conf

MongoDB on a Windows 7 machine: No connection could be made

After I have started Mongo using mongod.exe on a Windows 7 machine, I tried to start the mongo shell that failed with the error:
Failed to connect to 127.0.0.1:27017, reason: errno:10061 No
connection could be made because the target machine actively refused
it.
...
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
In the CMD where I running the mongod the output is:
C:\Users\Vera>mongod --dbpath c:\mongodb\mongodata
2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB starting :
pid=3296 port=27017 dbpath=c:\mongodb\mongodata 64-bit host=Vera-PC
2014-05-18T17:10:10.136-0300 [initandlisten] targetMinOS: Windows
7/Windows Server 2008 R2
2014-05-18T17:10:10.136-0300 [initandlisten] db version v2.6.1
2014-05-18T17:10:10.136-0300 [initandlisten] git version:
4b95b086d2374bdcfcdf2249272fb552c9c726e8
2014-05-18T17:10:10.136-0300 [initandlisten] build info: windows
sys.getwindowsversion(major=6, minor=1, build=7601, platform=2,
service_pack='Service Pack 1')
BOOST_LIB_VERSION=1_49
2014-05-18T17:10:10.136-0300 [initandlisten] allocator: system
2014-05-18T17:10:10.136-0300 [initandlisten] options: { storage: {
dbPath: "c:\mongodb\mongodata" } }
2014-05-18T17:10:10.242-0300 [initandlisten] journal
dir=c:\mongodb\mongodata\journal
2014-05-18T17:10:10.243-0300 [initandlisten] recover : no journal
files present, no recovery needed
2014-05-18T17:10:11.077-0300 [initandlisten] waiting for connections
on port 27017
Any suggestion how to fix this issue?
I got the same error and fixed it with:
1) mkdir c:\data
2) cd data
3) mongod -dbpath .
4) Now in another command window I was able to connect from my client using the mongo command.
I got this problem. What fixed mine is:
Suppose you have a dir: "C:\mongo_databse"
Open Command Prompt and type (suppose you haved added the Mongo bin directory to PATH): mongod --dbpath=C:/mongo_database.
There will be some log to the command prompt.
Now open ANOTHER command prompt then type in mongo then it works.
What solved my issue was creating a file startmongo.conf that sets the bind_ip to 127.0.0.1 . After that, I just created a *.bat to start the mongo using something like:
mongod --config c:\mongodb\bin\startmongo.conf
More details could be seem at this post .
I assume your mongo.config file to be located inside the mongodb folder in the same level to the bin directory.The contents of the mongo.config file are:
dbpath=C:\mongodb\data
logpath=C:\mongodb\log\mongo.log
diaglog=3
don't forget to create the data folder and log folder in the same level of bin directory inside log folder create the mongo.log empty file.
Point your command prompt to C:\mongodb\bin wherever your mongo db bin folder is located.
create the mongo db service in windows typing
mongod.exe --storageEngine=mmapv1 --config=../mongo.config
from now unwards you can start the mongo db service as
net start mongodb
finally you can connect to the mongo db server from the mongo db client typing
mongo.exe
once you have gone successfully from step 1 to step 3 from the next time on wards you only need the step 4 and 5.to start the service and to connect.
it prompted me like this
1)So, i created a path
C:\data\db
2)Now run
mongod in your terminal
it solved me issue!
I got this error beacuse of not sufficient space in the disk.
Check your mongo log.
I was getting a similar error when I was trying to start my mongo db via cmd. However the difference was I had a config file which has the path to the db and log folders and wanted to use the same. I was using mongo few days back and it was running fine but when I started using it again today it was giving me the error :
2015-05-27T10:33:22.820-0400 I CONTROL Hotfix KB2731284 or later update is installed, no need to zero-out data files
MongoDB shell version: 3.0.2
connecting to: test
2015-05-27T10:33:23.854-0400 W NETWORK Failed to connect to 27.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2015-05-27T10:33:23.857-0400 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed
Here's how I fixed it :
Open cmd as admin and navigate to the bin folder of your MongoDB and type : mongod --config <path to your config file> --install
Now start your mongo db service : net start mongodb
you should get a message which says : The MongoDB service was started successfully.
close this command prompt and open another one as admin, navigate to the bin folder once again and type mongo
This will connect you to the mongodb test.
Press ctrl+c anytime to exit.
Hope this helps.
In Windows 10:
Executing below command restarts mongodb service (as administrator), required if there is a system restart after mongodb installation.
net start mongodb
Also make sure to check, if there is a MongoDBInstallation folder/data and /data/db folder created, same can be obtained at MongoDBInstallation\bin\mongod.cfg
mongod --dbpath=c:\MongoDBInstallation\data\db
Open task manager, click on the services tabs on the top. From the list right click on mongoDB then click start.
I had a very similar experience to #user1501382, but tweaked everything slightly in accordance with the documentation
1) cd c: //changes to C drive
2) mkdir data //creates directory data
3) cd data
4) mkdir db //creates directory db
5) cd db //changes directory so that you are in c:/data/db
6) run mongod -dbpath
7) close this terminal, open a new one and run mongod
for mongodb 3.0 versions use "--smallfiles".
e.g:-
mongod --dbpath="C:\Program Files\MongoDB\Server\3.0" --logpath="C:\Program Files\MongoDB\Server\3.0\data\log.txt" --smallfiles --install
I am not sure if there is a better way to run it.
For me, I use these settings to create a directory and to a determinate new path for the MongoDB.
The important thing for me is that I miss to run it as a server (mongod) and after that into another terminal I type mongo which provide me an option to use the database.
I hope this could help someone.
I found my answer on this page. https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-3.1&tabs=visual-studio
So, first, make a folder for your data; then, open one command shell
mongod --dbpath <data_directory_path>
then, open another shell, do whatever you want to do. You can see in MongoDB Compass, there are collections if you had one before.
I tried the above answer
, and it worked, but had a very important problem: My previous collections were lost in another mongoDB data folder which I didn't know where they are and how to get them back.
Before I run in to this mongo error, I was running mongo with no problem. When my windows10 boot files got corrupted and My computer went into blue screen, mongo ran into this error. So I just tried to retrieve the previous condition which I just was running mongo in one terminal and not mongod in another, so
I repaired mongoDB with it's installation exe file, and now everything is ok.
This is my mongoDB specs: mongodb-win32-x86_64-2012plus-4.2.1
Hope this help you too.
Just type mongod in one command prompt and then run mongo in another.
Simply follow the following steps mostly your problem will be solved(Windows 10)
services->mongodb->change auto to run
you can go to services>>Mongo DB server .. right click and press start . This worked for me
By simple step ,I was resolve this problem
first step - make a New folder in C-drive in PC with name - "data"
second step- now open this "data" folder
Third step - Inside the "data" folder, again make a new "db" folder
Note - Just leave it this both folder empty, no need to add any content inside this,
and run "mongo" and "mongod" in PowerShell of your PC.
I got the same error, and this is how I resolved it,
follow the below steps:-
Open mongod.cfg file
Add the bindIpAll: true tag in the
net (Network Interfaces) section
restart the mongoDB services.
# network interfaces
net:
port: 27017
bindIpAll: true
#bindIp: 127.0.0.1

Cannot start MongoDB as a service

I have been developing for MongoDB for some months now and would like to install it as a service on my Windows 7 Enterprise machine. The following is the command that I have executed to create the service:
"D:\Milvia Systems\Development\MongoDB\mongod.exe" --logpath "D:\Milvia Systems\Development\MongoDB\logs\DBLog.log" --logappend --dbpath "D:\Milvia Systems\Development\MongoDB\db" -vvv --reinstall
However, whenever I use net start "MongoDB" or the Service Control Panel I receive the following error:
Error 1053: The service did not respond to the start or control
request in a timely fashion.
Environment: Windows 7 Enterprise 64bit
MongoDB: 1.6.3 pdfile version 4.5
Have your checked you logging to see the real problem?
I suggest extracting the Mongo installation to c:\mongodb.
Create the c:\mongodb\logs and the c:\mongodb\data\db directories.
Then browse the the c:\mongodb\bin directory and run the following to remove the service (if you've installed it!):
mongod --remove
Then install the service, specifying the log and data directories:
mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install
Then if there is a problem starting the service you should see the reason in the specified log file.
More info here.
If you did not specify absolute file paths for the data directory, or the log directory, you will get the same Windows error, but no log file.
I used the information from "Install MongoDB Service on Windows 7", pushed on Webiyo to correct the registered service arguments:
Download MongoDB and extract it to the C:\ drive.
Add "data" and "logs" subdirectories under the "C:\mongodb165" directory.
Add a log file name "mongolog.txt" at "C:\mongodb165\logs\mongolog.txt".
Change the directory to "C:\mongodb165\bin".
Execute the following command:
mongod --install --rest –master –logpath=C:\mongodb165\logs\mongolog.txt
Open the registry editor (regedit.exe), go to HKEY_LOCAL_MACHINE → SYSTEM → CurrentControlSet → Services.
Find the MongoDB key and set the "ImagePath" value to:
C:\mongodb165\bin\mongod --service --rest --master --logpath=C:\mongodb165\logs\mongolog.txt --dbpath=C:\mongodb165\data
Save the changes to the registry and exit the registry editor.
Open ComponentServices, click on "Services (Local)", and find the MongoDB service. Start it.
Check at the URL http://localhost:28017/ to verify that MongoDB returns stats.
I just encountered the same issue on my windows 7 machine. I followed the directions in MongoDBs Docs for the install, but it wouldn't let me execute "net start MongoDB" unless I was in "C:\". I didn't want to go back and reinstall MongoDB to follow the instructions included in the Webiyo link referenced above though. If you already installed MongoDB according to their docs and want to be able to execute "net start MongoDB" from where ever your project directory is:
Go to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB
Double click ImagePath under the Name column
Paste in the following ImagePath ( edit the folder directory and names to match your needs ):
C:\mongodb\bin\mongod.exe --service --rest --master --logpath=C:\mongodb\log\mongolog.txt --dbpath=C:\mongodb\data\db --config C:\mongodb\mongod.cfg
Note that if you direct copy this ImagePath value and your "data" folder is in the mongodb directory instead of C:\ add the following line to your "mongod.cfg" file: dbpath=C:\mongodb\data\db
After I did this, when I run "net stop MongoDB" I get the message "System error 109 has occurred. The pipe has been ended." You may see it as well. This message has been discussed thoroughly at jira.mongodb.org.
To save you the time of reading the whole back and forth discussion, Tad Marshalls post sums up this issue:
"... it was working fine in 2.1.0; later changes broke it again. But yes, you get this error message in the current code.
The explanation is that mongod.exe is exiting from a callback thread created by the Windows Service Control Manager when it calls us due to "net stop mongodb" and this breaks the RPC pipe it used to create the callback thread. We need to reorganize our exit logic to avoid doing this.
The error message is the only real effect of this issue; we exit on command, cleanly, and inform the Windows Service Control Manager that we are stopped, but then the "net" command displays an error message because we didn't return from the RPC call the way it expected us to."
My mongod.cfg file had the following last two lines:
#snmp:
mp:
I have no idea why there's an mp: in there. But when I manually executed the image path
C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
at
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB
I got
c:\mongodb\bin>mongod /?C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
Unrecognized option: mp
try 'mongod --help' for more information
So I commented it out and then the service started without any problem.
These are the steps I followed to install mongoDB on windows 7
download the .msi file from the mongodb site--> https://www.mongodb.com/download-center?jmp=nav#community and run it
Wherever your mondoDb is downloaded (generally in the c drive Program Files folder), go to that folder and wherever is the bin folder in that same folder create your data folder and your log folder
3.Inside your data folder create your db folder
The structure would look something like this
Now open command prompt as administrator.
change your file path and enter the bin folder.( in this case it would be c>program files>MongoDB>bin> )
Type in the following command : mongod --directoryperdb --dbpath "C:/Program Files\MongoDB\data" --logpath "C:\Program Files\MongoDB\log\mongo.log" --logappend --rest --install
This would set the logpath and database path. Lastly run net start MongoDB . Hope this helps.
I ran this command:
C:\MongoDB\Server\3.4\bin>net start MongoDB
And got this message:
The service is not responding to the control function. More help is
available by typing NET HELPMSG 2186.
After some trials and errors, I noticed when following the tutorial it asked me to name my file mongod.conf but the command was trying to refer to mongod.cfg.
As soon as I corrected that name and re-run the commands,
C:\MongoDB\Server\3.4\bin>sc.exe delete MongoDB
[SC] DeleteService SUCCESS
C:\MongoDB\Server\3.4\bin>sc.exe create MongoDB binPath= "\"C:\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService SUCCESS
C:\MongoDB\Server\3.4\bin>net start MongoDB
The MongoDB service is starting....
The MongoDB service was started successfully.
The service started running fine.
To others who may have the same problem on Windows Server 2012:
I have just got the same problem with Mongo 3.0.3 on Windows Server 2012. I am not a system admin so I don't know what they have changed for sc.exe. I have to use
sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "auto"
This is without the \"\" for both binary and config file paths comparing to the one on their website.
For mongoDB 3.0, You will have to set the following in the config file.
logpath=E:\mongoDBdata\log\mongoDB.log
dbpath=E:\mongoDBdata\db
the logpath should end with a file and not a folder.
Check if your mongod.cfg file has tabs in it. Removing tabs solved it for me!
Following works with MongoDB 3.6.0
Make sure you have these folders:
C:\mongodb\data
C:\mongodb\data\db
Then all you need are these commands:
mongod --directoryperdb -dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --service --install
net start MongoDB
mongo
Another way this might fail is if the account running the service doesn't have write permission into the data directory.
In that case the service will be unable to create a lock file.
The mongod service behaves badly in this situation and goes into a loop starting a process, which immediately throws an unhandled exception, crashes, etc. the log file gets recreated every time the process starts up, so you have to grab it quick if you want to see the error.
the default user for windows services would be localhost\system. so the fix is to ensure this user can write into your db directory, or start the service as another user who can.
For version 2.6 at least, you must create the /data/db/ and /log/ folders that the mongo.cfg points to. MongoDB won't do so itself, and will throw that error in response when ran as a service.
make sure to open the command line with "run as administrator" rights in the right click before typing the entire mongod things
Just try to run mongod.exe locally in command line, you can get here exception, that mongod calls and try to solve it. In my case it was small free space on local disc, so I just change location of directories and change Mongocofig file and now it run ok.
After spend half an hour on debug ... I finally found that there is single dash before the "rest" attribute.
If you look in the service details, you can see that the command to start the service is something like:
"C:\Program Files\MongoDB\bin\mongod" --config C:\Program Files\MongoDB\mongod.cfg --service
The MongoDB team forgot to add the " around the --config option. So just edit the registry to correct it and it will work.
I had same issue on windows 8.1
The solution which worked for me is to specify config file path correctly
Going to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB > imagePath the value was like the following:
"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --config mongod.cfg --service
Then just I corrected config file path to match my actual path:
"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --config "d:\mongodb\mongod.cfg" --service
Remember to create the database before starting the service
C:\>"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath d:\MONGODB\DB
2016-10-13T18:18:23.135+0200 I CONTROL [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
2016-10-13T18:18:23.147+0200 I CONTROL [initandlisten] MongoDB starting : pid=4024 port=27017 dbpath=d:\MONGODB\DB 64-bit host=mongosvr
2016-10-13T18:18:23.148+0200 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-10-13T18:18:23.149+0200 I CONTROL [initandlisten] db version v3.2.8
2016-10-13T18:18:23.149+0200 I CONTROL [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-10-13T18:18:23.150+0200 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-10-13T18:18:23.151+0200 I CONTROL [initandlisten] allocator: tcmalloc
2016-10-13T18:18:23.151+0200 I CONTROL [initandlisten] modules: none
2016-10-13T18:18:23.152+0200 I CONTROL [initandlisten] build environment:
2016-10-13T18:18:23.152+0200 I CONTROL [initandlisten] distmod: 2008plus-ssl
2016-10-13T18:18:23.153+0200 I CONTROL [initandlisten] distarch: x86_64
2016-10-13T18:18:23.153+0200 I CONTROL [initandlisten] target_arch: x86_64
2016-10-13T18:18:23.154+0200 I CONTROL [initandlisten] options: { storage: { dbPath: "d:\MONGODB\DB" } }
2016-10-13T18:18:23.166+0200 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=8G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-10-13T18:18:23.722+0200 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-10-13T18:18:23.723+0200 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/MONGODB/DB/diagnostic.data'
2016-10-13T18:18:23.895+0200 I NETWORK [initandlisten] waiting for connections on port 27017
Then you can stop the process Control-C
2016-10-13T18:18:44.787+0200 I CONTROL [thread1] Ctrl-C signal
2016-10-13T18:18:44.788+0200 I CONTROL [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
2016-10-13T18:18:44.789+0200 I FTDC [consoleTerminate] Shutting down full-time diagnostic data capture
2016-10-13T18:18:44.792+0200 I CONTROL [consoleTerminate] now exiting
2016-10-13T18:18:44.792+0200 I NETWORK [consoleTerminate] shutdown: going to close listening sockets...
2016-10-13T18:18:44.793+0200 I NETWORK [consoleTerminate] closing listening socket: 380
2016-10-13T18:18:44.793+0200 I NETWORK [consoleTerminate] shutdown: going to flush diaglog...
2016-10-13T18:18:44.793+0200 I NETWORK [consoleTerminate] shutdown: going to close sockets...
2016-10-13T18:18:44.795+0200 I STORAGE [consoleTerminate] WiredTigerKVEngine shutting down
2016-10-13T18:18:45.116+0200 I STORAGE [consoleTerminate] shutdown: removing fs lock...
2016-10-13T18:18:45.117+0200 I CONTROL [consoleTerminate] dbexit: rc: 12
Now your database is prepared and you can start the service using
C:\>net start MongoDB
The MongoDB service is starting.
The MongoDB service was started successfully.
Check if a process instance of mongod is already running. If yes, this service will not start because C:\data\db\mongod.lock will be used by it.
And to start MongoDB as a service, this file shall be not used by any process.
For me, the issue was the wrong directory. Make sure you copy paste the directory from your file explorer and not assume the directory specified on the docs page correct.
If you receive the error:
the service name is invalid
when running net start mongodb, you will need to run the following command from Step 4 of Manually Create a Windows Service for MongoDB Community Editition:
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
I had made few changes in the Config start-up file, which caused this issue. When I looked in the "mongo.log" file, it said
"Cannot start server. Detected data files in E:\Mongo\data\db created by storage engine 'wiredTiger'. The configured storage engine is 'mmapv1'., terminating"
Resetting the storage engine back to 'wiredTiger' resolved the issue for me. Hope this helps others.
When I update the mongodb from 3.4 to 3.6 the described problem occurred, and I found that the problem can also be raised by regedit settings from old versions as residual.
So open regedit through command line then check the value under ImagePath in \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB, make sure that both the absolute paths and suffices are correct.
In my case, the reinstallation didn't update the settings of suffices for me, so the suffices --httpinterface and --rest remained in the regedit, while those were removed in mongodb 3.6.
I started following a tutorial on a blog that required MongoDB. It had instructions on downloading and configuring the service. But for some reason the command for starting the Windows service in that tutorial wasn’t working. So I went to the MongoDB docs and tried running this command as listed in the mongodb.org-
The command for strting mongodb service-
sc.exe create MongoDB binPath= "\"C:\MongoDB\bin\mongod.exe\" --service --config=\"C:\MongoDB\bin\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
I got this message: [SC] CreateService SUCCESS
Then I ran this one:
net start MongoDB
And got this message:
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
I create a file named 'mongod.cfg' in the 'C:\MongoDB\bin\mongodb\'
As soon as I added that file and re-ran the command- 'net start MongoDB', the service started running fine.
Hope this helps.
Well, in my case, I was running low disk space on my drive where I have my MongoDB data files. I checked MongoDB logs file which stated the following
2015-11-11T21:53:54.717+0500 E JOURNAL [initandlisten] Insufficient free space for journal files 2015-11-11T21:53:54.717+0500 I JOURNAL
[initandlisten] Please make at least 3379MB available in
C:\wamp\bin\mongodb\data\db\journal or use --smallfiles
All I had to do is clean up some space and fire up the service again.. Worked for me. So All you have to is check your logs file and deal with the problem accordingly.