My MongoDB authentication config is not working - mongodb

I installed MongoDB using homebrew on my mac.
And I created admin account on my local mongodb.
Then, I added below code to my 'mongod.conf' to use authentication mode.
The code is 'security: authorization: enabled'.
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
security:
authorization: enabled
And I restarted MongoDB. 'brew services restart mongodb'
But whenever I start mongo shell, it still print
WARNING: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted.
And naturally it can be used without user connection.
How can I resolve this problem?
If I type
db.auth("username", "password")
It print '1'. <- authenticated.
Is it impossible to authenticate mongoDB if I use homebrew?
I don't know what I have to do anymore.
Please, Help me.
Thank you.
+ It's full log
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("573560e4-0a3a-472e-a94a-79b1cecab4fd") }
MongoDB server version: 4.0.3
Server has startup warnings:
2019-08-27T19:02:40.847+0900 I CONTROL [initandlisten]
2019-08-27T19:02:40.847+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-27T19:02:40.847+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-08-27T19:02:40.847+0900 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()

try removing the current service
enable authorization first in the config file and then run mongod daemon for the very first time.
mongo allows "localhost exception". Read about it in the documentation
then create first account with required privileges on the admin database. Make sure to include privileges of creating other users.
restart mongod daemon.
check if error goes away..
point is to enable authorization before creating any user, even before admin.

I don't see you have specified the Authentication Mechanism in config file. Please add it to your mongod config file
security:
authorization: enabled
setParameter:
authenticationMechanisms: SCRAM-SHA-1
Once the above is done, restart your mongo instance and that should work

Related

How to enable access control for MongoDB with Docker (Plesk)

How do I enable access control for my MongoDB server?
This line shows up in the log:
CONTROL [initandlisten] ** WARNING: Access control is not enabled for
the database. I CONTROL [initandlisten] ** Read and write access to
data and configuration is unrestricted.
I use Plesk to start MongoDB and I have read their manual about it
but it doesn't tell me how to enable access control since I can only add environment variables and volume mapping via the Plesk control panel such as /data/db and /data/configdb.
I'm able to use a terminal to login without credentials to create a superadmin and all the roles, but that doesn't solve the unrestricted access.
I can also access files within the container with this:
docker exec -it mongo /bin/bash
And I see this directory: docker-entrypoint-initdb.d
but I don't know what to put there. Also packages that I installed inside the container like vim don't persist and are lost after a restart.
Furthermore I have no idea where Plesk is storing the docker-compose.yml file. Is this a file that only belongs inside a image file?
If I change the /etc/mongod.conf and add this:
security: authorization: enabled
nothing happens after restart, could I get some help with this?
system information:
Plesk Onyx 17.8.11 Update 25
Host: CentOS 7.5.1804
Container: Ubuntu 16.04
Docker version 18.06.1-ce, build e68fc7a
You should read the library/mongo image documentation : https://hub.docker.com/_/mongo/
If you want to use your own mongo configuration file, put it somewhere like /etc/mongo/mongod.conf in your container (with volume or COPY).
After that you have to tell to mongo to use it as configuration file :
$ docker run --config /etc/mongo/mongod.conf
Or in docker-compose :
services:
mongo:
image: mongo
command: --config /etc/mongo/mongod.conf
I can't help you for the location of Plesk docker-compose.yml, try to use find command.
I hope it will help you.

How can i restrict the user in MongoDB?

I have created user with read permissions in Mongodb. I have done the same process here
but still user was not restricted with permissions.User can create the collection and insert the document but user have only read permissions.
When I opened mongo.exe, it was showing some warnings.
ongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0
Server has startup warnings:
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten]
**2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.******
2018-09-17T01:11:07.042-0400 I CONTROL [initandlisten]
---
So how can i restrict the user in MongoDB?
So, you are missing few things in configure section.
you need to activate in the mongod configuration file.
it will be located in /etc/mongod.conf if you are using Linux.
you need to change/uncomment/add this section below:
security:
authorization: "enabled"
and after that you need to restart mongod service.
in my case service name is mongod .
so i did sudo systemctl restart mongod .
and as you already having role. and authentication enabled just now.
you have to login now.
>> mongo --port <YOUR_MONGO_PORT>
> use admin
> db.auth("username","password")
it should login now.
all steps:
Create Users with needed Roles.
Enable Authetication in DB config level.
Dont forget to Restart The Database service.
Try To login. You are Good to Go.
You can look into this medium post as well here.

authentication in MongoDB and Ubuntu

We installed MongoDB on windows(development) version 3.4, and enabled authentication, after running the command mongod --auth, the authentication was successfully implemented.
Now on the production server that is Ubuntu 16, with MongoDb version 4.0, we made changes to the mongod.conf file as seen below and then restated the mongod service with command sudo service mongod start, but now we are not able to connect to our MongoDB Ubuntu server.
security:
authorization: "enabled"
Where did we go wrong in implementing authentication for MongoDB on Ubuntu server.
security:
authorization: "enabled"
2 possible issues here : reading the doc, i'm not sure you need to quote the enabled word.
Moreover, yaml format need to increment sub part of conf, so your conf file have to look like :
security:
authorization: enabled
But cannot really test, since i don't have any running local instance

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

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.