Cannot start MongoDB as a service - mongodb

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.

Related

Robo 3T Error : Network is unreachable

I am trying to connect Robo 3T to my online database and it doesn't seem to be working. I am able to connect to local database with it. I tried connecting using MongoDB Compass and the Details and Auth are working fine and I am able to connect. But when I connect with the same details in Robo 3T, it doesn't seem to be working. How do I fix this?
I am using Robo 3T Version 1.1
I tried same with Robomongo 1.0, and still getting the same error
Just change your bind_ip in /etc/mongod.conf from 127.0.0.1 to 0.0.0.0 then restart the service, and it works for me~
If you get the following error then you should also check the following:
The atlas servers at least require this setting, if you do not choose it, then you generally get the Network is unreachable message.
Also if you are using Atlas then you should check the Authentication tab and select SCRAM-SHA-1, however this generally results in an authentication error not a network unreachable one.
A better solution is to comment out or remove the bindIp setting from the config file /etc/mongod.conf
You must restart the service for the change to take effect
I also meet this problem when I use Robo 3T on Mac. I think there are some things you need to check to help you know what's the problem.
First try to ping the mongo server in your terminal to see whether you can get responses. If so, that's means you may set wrong mongo config in you Robo 3T.
If you cannot get the response, that means there is something wrong with your network. You should check your DNS and your network gateway. For example my DNS is 172.16.* and my network gateway (execute ifconig and check en0) is 172.17.*. And they are not belong to the same network segment. (Actually, even if they are on the same network segment, things won't work if someone polluted your DNS server.)
That's the problem. The DNS that you are using cannot interpret your mongo host correctly. Someone may had polluted this DNS server.
You can have a try on ping xxx(your mongo-server) #8.8.8.8, which will use 8.8.8.8 as your DNS. If everything goes well, then you get the sollution.
Sollution: Manually set DNS for your devices. For example, Google's public DNS, 8.8.8.8 and 8.8.4.4.
Actually, if you run dig xxx(your mongo-server) before and after you manually set DNS, you may find the response Ip differently.
Go Inside bin folder of MongoDB and run mongod command:- C:\Program Files\MongoDB\Server\4.2\bin
then open command prompt at this location and run mongod command & then try to connect with Robo 3T . It works for me.
Also create data folder inside your C: drive & then create a db named folder inside data folder. that's it.
Start the MongoDB service from the task manager.
Worked for me.
In my case both mongod and mongo.exe was throwing a 100 error code.
I had this symptom, and the ultimate fix is not yet captured in an answer here.
I was trying to connect to a mongo instance in the cloud using Robo 3T, and I was getting the "Network is unreachable" message.
Oddly, I could connect from using Robo 3T inside a Parallels VM on the same machine.
This led me to try the full Studio 3T on my mac, which could also connect just fine.
Ultimately, I discovered that there was an old dotfile from an ancient version of Robomongo that was causing the problem. rm -rf .config/robomongo did the trick. Now I can connect with the ordinary, free Robo 3T.
I'm guessing that I had an expired trial of Robomongo, from back before it was free, perhaps?
sorry if i'm late to this but i was running through the same issue all morning. You have to go through a few things first so you can troubleshoot easily
Restart the database from the terminal, hitting the database at the correct path and let it run in the background.
if the database is running then go through checking the local host address, and replace it with 127.0.0.1 instead of the generic localhost:27017
This might help, my robo mongo server is hosted in cloud. I have setup the mongodb but could not connect to it using Robo3T. Keeps telling network timedout (this means network problem). Been reading a lot to figure out the cause, suddenly I remembered I have also a security group in my cloud network. Just include the mongod port 27017 in the list of allowed incoming. That's it!
You may be seeing the following issue when starting the Robo 3T Application:
Just follow these steps, and you are good to go:
I'm using MacOS, so in your terminal use the following command to start your MonogDB Server:
/Users/vanthoff/mongodb/bin/mongod --dbpath=/Users/vanthoff/mongodb-data
mongodb-data: Directory you must have created to store all your Data.
After starting the server, go to RoboT 3T Application and connect to the server. It will start working. You can also Test it by double clicking you MongoDB Server name. It will look something like this when it starts working:
I hope it's going to work for you too. Amigos..!! 🙂
Go to services.msc and then search for mongodb server and then run the server in running status.
I have solved my error in this way.
For me, reinstall mongodb and restart my computer worked fine.
As said above, this is probably due to BindIp, if you use mac and brew to install it you won't find anything in /etc/mongod.conf instead you find it in /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
Change BindIp with caution!
And same goes for running it, to start MongoDB manualy use:
mongod --config /usr/local/etc/mongod.conf
or configure autostart on login with launchd by typing:
brew services start mongodb
I've also encountered corrupted data files on my local computer here:
/usr/local/var/mongodb
just removed them and it worked, you could see in the log that errors like:
** IMPORTANT: UPGRADE PROBLEM: The data files need to be fully upgraded to version 3.6 before attempting an upgrade to 4.0; see http://dochub.mongodb.org/core/4.0-upgrade-fcv for more details.
2018-08-01T00:15:50.220+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-08-01T00:15:50.220+0200 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-08-01T00:15:50.224+0200 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2018-08-01T00:15:50.303+0200 I STORAGE [initandlisten] Downgrading WiredTiger datafiles.
2018-08-01T00:15:50.501+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:501686][3594:0x7fffb492e380], txn-recover: Main recovery loop: starting at 14/3712
2018-08-01T00:15:50.598+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:598867][3594:0x7fffb492e380], txn-recover: Recovering log 14 through 15
2018-08-01T00:15:50.664+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:663976][3594:0x7fffb492e380], txn-recover: Recovering log 15 through 15
2018-08-01T00:15:50.715+0200 I STORAGE [initandlisten] WiredTiger message [1533075350:715398][3594:0x7fffb492e380], txn-recover: Set global recovery timestamp: 0
2018-08-01T00:15:51.002+0200 I STORAGE [initandlisten] shutdown: removing fs lock...
2018-08-01T00:15:51.005+0200 I CONTROL [initandlisten] now exiting
2018-08-01T00:15:51.005+0200 I CONTROL [initandlisten] shutting down with code:62
This means mongo server is not started.
You need to run mongod command on the terminal to start the server.
if you do not have mongo db installed on your machine. Download and install from the Link.
Start your command prompt on windows.Go to the bin folder of Mongodb through command prompt and type mongod and enter.Now try to access again

MongoDB : A Service Specific error occurred :100

I have just installed "mongodb" on Windows, while starting it, the following error appears
A Service Specific error occurred :100
Any Suggestions?
The reason for this error message is that you have another process already established.
In my case it was the mongod.exe file I had opened in CMD, when I closed it and restarted the net start MongoDB command, it connected successfully.
BTW i am using Windows 10 current build as of July 2017 with MongoDB 3.4
Please try running the below commands as Administrator in the comment prompt.
mongod --repair
mongod --remove
then like #Yahya did, specify the log path,
mongod --install --logpath C:\data\db\log\mongo.log
net start mongodb
Hope it helps.
For me, somehow directories I have specified for db and log config file were not auto created.
dbpath=\data\db
logpath=\data\log\mongo.log
so I created them manually then ran the command again and service started.
I am using v3.4.9 om Windows 10
Check your Mongo log in your /data/log folder (which you should have created during install), there might be a solution in there.
I had this issue, I checked the System Event Log which gave me the following:
The MongoDB service terminated with the following service-specific error: Cannot create another system semaphore.
When I checked the log I found this:
Unable to create/open lock file: c:\data\db\mongod.lock The process cannot access the file because it is being used by another process.. Is a mongod instance already running?
Turns out I'd started the process manually in another command window so it couldn't start it again. You may have a different issue but the log should tell you what is going on!
execute the command
"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe"
and check which error is displayed
Running mongod.exe through a service does not display the error messages. In my case, i didnt created the directory /data/db, which i specified in my configuration file. My Configuration file is based on the docs create-a-configuration-file
The error was only displayed after executing the command directly
For example mongoDB version 3.6 is installed, and the installing path of MongoDB is "D:\Program Files\MongoDB".
Create folder D:\mongodb\logs, then create file mongodb.log inside this folder.
Run cmd.exe as administrator,
D:\Program Files\MongoDB\Server\3.6\bin>taskkill /F /IM mongod.exe
D:\Program Files\MongoDB\Server\3.6\bin>mongod.exe --logpath D:\mongodb\logs\mongodb.log --logappend --dbpath D:\mongodb\data --directoryperdb --serviceName MongoDB --remove
D:\Program Files\MongoDB\Server\3.6\bin>mongod --logpath "D:\mongodb\logs\mongodb.log" --logappend --dbpath "D:\mongodb\data" --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install
Remove these two files mongod.lock and storage.bson under the folder "D:\mongodb\data".
Then type net start MongoDB in the cmd using administrator, the issue will be gone.
This error occurs due to that service is already started. If you are not done it, then please check your database path and log path in the mongodb.cfg (The file which stores mongodb configuration) file.
Eg:
systemLog:
destination: file
path: H:\data\log\mongod.log
storage:
dbPath: H:\data\db
processManagement:
windowsService:
serviceName: "MongoDB"
displayName: "Mongo DB"
description: "mongod service"
If you doesn't have it then please create one.
Also you can use the following step to fix this issue,
please run the follow as administrator.
sc.exe qc MongoDB
If there are no logs, then MongoDB likely cannot open the log file due to a permission issue.
Also, try installing the service as
D:\servers\db\mongodb\bin\mongod.exe --dbpath=D:\servers\db\mongodb\data --logpath=D:\servers\db\mongodb\log\mongo.log --logappend --install
I fixed my issue
In the config one of the path was
C:\MongoDB\data\db
But nor the data or db folder existed
I expected them to be generated automatically.

Windows could not start mongodb service on local computer. For more info., review the System Event Log

I am using Windows 32-bit machine and tried to start MongoDB service from Windows > services as shown below.
However, I am unable to start the MongoDB service from it and throws the following error.
When I try using cmd prompt, I am getting the following error:
Network 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.
I had same an issue.
Try to remove mongod.lock file from your Mongo data directory.
For example mine is "C:\Program Files\MongoDB\Data\mongod.lock" and after deleting file start the MongoDB service and it's work like charm.
In case someone else is running into this problem, just read your Log files and you will be able to find the problem, for me after trying to install it inside wamp directory when I run the MongoDB service it gave me the same error message, I went to the logs and find out that I was missing a directory inside my data directory which is called db, once I have created this directory the service run perfectly.
MongoDB uses a default folder to store its files. On Windows, the default location is C:\data\db.
Maybe that folder doesn´t exist. In that case just creat it or change the default location of Mongo service using the --dbpath command-line flag.
So I just had the same problem, running on Windows 10. The reason why MongoDB didn't start was because the path to the data and logs was not correctly set. This has already been pointed out, but my solution is different. Look in C:\Program Files\MongoDB\Server\4.0\bin (or wherever your mongoDB is installed). There is a config file called mongod.cfg. Check that
storage:
dbPath:
and
systemLog:
path:
Is set to what you want. In my case, it was using environment variables %MONGODBPATH% or similar that was not set by Windows. By default, the log and data should point to C:\Program Files\MongoDB\Server\4.0\data and C:\Program Files\MongoDB\Server\4.0\log\mongod.log respectively.
There was a npm: in last line of mongodb configuration file which is located in the installation folder in the bin\mongod.cfg
I commented out that line and started the service and it is working like charm.
I concluded this by running the mongodb service command from windows command line(cmd) and I got an error.
I ran this to spot the error:
C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe --config "C:\Program Files\MongoDB\Server\4.2\bin\mongod.cfg" --service
mongod.lock deletion did not helped me, repair did not help either. In my case it was due to one of database happened to be corrupted, I moved all dbs to another directory and then copied them back one by one and re-starting mongodb service to figure out what db file is corrupted. It's definitely MongoDb bug
I had the same error message. Try to locate the mongodb log files and look at the last entries. My issue was clearly stated there, a missing directory :
2019-01-29T16:59:44.424+0100 I STORAGE [initandlisten] exception in
initAndListen: NonExistentPath: Data directory
C:\wamp64\bin\mongodb\mongodb-win32-x86_64-2008plus-ssl-3.6.10\data\db
not found., terminating
The advice of checking the log was what helped me. In this case:
The MongoDB service could not be started. A service specific error occurred: 100
turns out I had a problem with some databases created with WiredTiger while the mongod.cfg specified engine was: mmapv1
So I basically removed the content of the folder c:/data/db/ and then used the command net start MondoBD --repair and worked. Uffff it´s been 2 days.
I'm here a bit late, very late actually. But may it works something out for the ones facing this issue now. Mongodb configuration file in Windows OS is under 'C:\Program Files\MongoDB\Server\%YOUR MONGO VERSION%'.
I had changed this file and manipulated the bindip field, so I was getting the same error. It should be 127.0.0.1 or your machine's IP address which you can find it by 'ipconfig/all' command in cmd. So I fixed bindip and the service starts with no problems.
stuck on the same issue, but got the solution by hit and trial, just create a new folder for path "C:\data\db" then go to your command prompt and type 'mongod', your database server will start.
For me it was a port problem :
just search and kill the process using the port 27017
for linux : https://bobcares.com/blog/mongodb-error-code-48/
for windows : How do I kill the process currently using a port on localhost in Windows?
I have found out that Visual C++ Redistributable was missing in my Windows 7 Machine. After installing it worked.
For Windows 10 users
specify database location, if don't know create the below-mentioned directory and always use this
open cmd
mkdir C:\users\{username}\data
cd C:\users\{username}\data
mongod --dbpath .
start mongodb server
open cmd
mongod --dbpath C:\users\{username}\data
stop mongodb
open cmd
mongo
if server is running, run:
use admin
db.shutdownServer()
quit()
In my case, this happened because I did not stop MongoDB from docker. after I stopped the process the error was gone.
In my case, it was the docker with MongoDB running on the same port. So after I stopped the container, the service is then successfully starting.

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

MongoDB won't start after server crash

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