Reputation: 172
When I start mongoDB server with Mongod
command it serves my mongoDB databases. But some times I get different set of databases. Which means when I stop the server with net stop MongoDB
and start server with mongod
command 'A','B','C' databases are showed. Then when I stop and again and start the server 'D','E','F' databases are showed.
What is actually happening. Is it running two instances or something time to time?
To be more clear
> show dbs
admin 0.000GB
codeProject 0.001GB
codeprojectData 0.017GB
config 0.000GB
local 0.000GB
projectData 0.285GB
database 1
is what I get when I run mongod at path: C:\Program Files\MongoDB\Server\4.0\bin
when I run net start MongoDB
at the same path I get
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
projetDataNew 0.004GB
questions 0.000GB
Upvotes: 0
Views: 101
Reputation: 576
Alright, this seems to be a config issue, to confirm this follow the below steps.
First open services in windows and check the properties of mongod command that you have installed, there you should be able to find the config file that you have provided while installing the service Here is a screenshot of the view of mongodb service in services panel: https://cdn.journaldev.com/wp-content/uploads/2014/11/MongoDB-Windows-Service.png
Once you have the path, try the below command: {path to your mongod.exe} --config { Path of the config file that you just copied from the services panel }
Now if you do >show dbs; the listed databases will be the same as the one of net start Mongodb.
I think when u start mongod from bin it will just use a default config file from the mongodb root folder if you have installed in c:\ then it will be inside C:\MongoDB\mongod.conf.
I am 100% sure that when u start mongodb through mongod the data directory is different than when u start it through net start mongodb, hence different databases.
Always try to create your own config file and use that config file to run mongod, so that you know what options you have provided, don't use mongodb default config.
Follow the above steps and let me know how it goes ;)
Upvotes: 1