Changing MongoDB 3.6 default db path in Windows - mongodb

I just installed a new MongoDB 3.6 on my Windows machine. Now I'm trying to change the default DB path. So I tried this:
"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --dbpath c:\mongodb\data
It worked, but only until I restarted Mongo. Then it was back to usual c:\data\db.
I tried to google it, saw some info about changing a mongod.conf file, but I can't find this file in my installation.
Any suggestions?

Save this script in a Batch File(Mongo.bat) and run it every time:
"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --dbpath c:\mongodb\data

You need to start mongod with same command everytime:
C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --dbpath c:\mongodb\data
Or you can create a configuration file and install mongo as a service.
.

Related

Unable to connect Mongodb

I have installed mongodb ans Studio 3T on windows 10, 64 bit system but when I run
mongod --auth --dbpath C:\data\db --storageEngine wiredTiger
this command, it says 'mongod' is not recognized as an internal or external command, operable program or batch file.
I am not sure why this error comes even mongo.exe and mongod.exe is available under "C:\Program Files\MongoDB\Server\3.0\bin" folder
Please help.
Yes, because you need to cd into the directory where the mongodb folders are created when you installed it.
For windows:- C:\Program Files\MongoDB\Server\3.6\ as per click here
Details Steps for you:-
cd C:\Program Files\MongoDB\Server\3.0\bin
check for mongo.exe, mongod.exe and etc.
mongod.exe --auth --dbpath C:\data\db --storageEngine wiredTiger
you should be able to connect now.
Note:- Above steps assumes that Mongodb service is running. If not Click here
OR you can add the path C:\Program Files\MongoDB\Server\3.0\bin to enviornment variable.
I have solved the problem, just added "C:\Program Files\MongoDB\Server\3.0\bin" path to environmental variable.

getting error while connecting to mongo.exe [duplicate]

I'm trying to run Mongo from the Command-Line:
What's wrong? (I've IIS on localhost:80). And Apache on port 8080. Are there any issues
with this?
C:\MONGO\Project1\mongo\bin>mongo --port 27017
MongoDB shell version: 2.0.3
connecting to: 127.0.0.1:27017/test
Sat Mar 10 16:16:45 Error: couldn't connect to server 127.0.0.1:27017 shell/mong
o.js:86
exception: connect failed
I found that when I got this error it wasn't because I didn't have my default db path set up. It was because I was trying to run mongo.exe before running mongod.exe.
Did you create the default db path?
It defaults to "/data/db directory (or c:\data\db on Windows)"
Source: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
As Admin, create directory:
mkdir c:\mongo\data\db
As Admin, install service:
.\mongod.exe --install --logpath c:\mongo\logs --logappend --bind_ip 127.0.0.1 --dbpath c:\mongo\data\db --directoryperdb
Start MongoDB:
net start MongoDB
Start Mongo Shell:
c:\mongo\bin\mongo.exe
Follow
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
Create config file in bin folder of mongo (or you may in save your desired destination).
Add following in text file named "mongod" and save it as
mongod.cfg
dbpath=c:\data\db
logpath=c:\data\log\mongo.log
or use following commands in command-prompt
echo dbpath=c:\data\db>> "mongod.cfg"
echo logpath=c:\data\log\mongo.log>> "mongod.cfg"
Now open command-prompt (administrator) and run the following command to start mongo server
mongod
Open another command-prompt (don't close 1st prompt) and run client command:
mongo
Hope this will help or you have done this already.
The error occurs when trying to run mongo.exe WITHOUT having executed mongod.exe.
The following batch script solved the problem:
#echo off
cd C:\mongodb\bin\
start mongod.exe
start mongo.exe
exit
If you are getting these type of errors when running mongod from command line or running mongodb server,
then follow these steps,
Create db and log directories in C: drive
C:/data/db and C:data/log
Create an empty log file in log dir named mongo.log
Run mongod from command line to run the mongodb server or create a batch file on desktop which can run the mongod.exe file from your mongodb installation direction. That way you just have to click the batch file from your desktop and mongodb will start.
If you have 32-bit system, try using --journal with mongod command.
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
you can use below command,
mongod --dbpath=D:\home\mongodata
where D:\home\mongodata is the data storage path
Go to C:\Program Files\MongoDB\Server\3.4\bin using cmd and
write mongod.
Open another cmd by right click and run as admin point to your
monogodb installed directory as mentioned above and then just like
write this mongo.exe
After that, write db.test.save({Field:'Hello mongodb'}) this command
will insert a field having name Field and value is Hello
mongodb.
After, check the record db.test.find() and press enter you will find
the record that you have recently entered.
Steps to start a certain local MongoDB instance and to connect to in from NodeJS app:
Create mongod.cfg for a new database using the path C:\Program Files\MongoDB\Server\4.0\mongod.cfg with the content
systemLog:
destination: file
path: C:\Program Files\MongoDB\Server\4.0\log\mongod.log
storage:
dbPath: C:\Program Files\MongoDB\Server\4.0\data\db
Install mongoDB database by running
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg" --install
Run a particular mongoDB database
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg"
Run mongoDB service
mongo 127.0.0.1:27017/db
and !see mongoDB actual connection string to coonect to the service from NodeJS app
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/db?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c7ed5ab4-c64e-4bb8-aad0-ab4736406c03") }
MongoDB server version: 4.0.9
Server has startup warnings:
...
For this error, if you are using windows 7 or windows server 2008 R2, the problem could be that you have to install a microsoft hotfix.
Refer to this link: https://support.microsoft.com/en-us/kb/2731284

How to start Mongo DB server from Windows?

I have installed MongoDB 3.6.3 on my Window 8.1(64 bit) machine. I have created the path data/db too but when I tried to start mongodb using the command 'C:\Program Files\MongoDB\Server\3.6\bin', it is not starting. It showing a message "the program can't start because api-ms-win-crt-convert-l1-1-0.dll is missing from your computer". Anyone help me to start Mongo DB server. Thanks in advance.
Open CMD
nevigate to C:\Program Files\MongoDB\Server\3.6\bin [Your mongodb installed location]
Then run command as mongod --dbpath E:\sangram\mongo_workspace --port 27017
[E:\sangram\mongo_workspace] is my local directory where i'll store my mongodb data

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.

MongoDB 3.0 Windows Service Start : System Error 2 has occured

I have downloaded the MongoDB Windows msi install and run this successfully.
The mongod.exe and mongo.exe command file executions work properly.
The installation manual shows how to create the configuration file, and then to create the Windows Server using the command
sc.exe create MongoDB binPath= "\"C:\mongodb\mongod.exe\" --service --config=\"C:\mongodb\mongod.cfg\""
This creates a SUCCESS response.
The service is then started
net start MongoDB
but this produces the response
System Error 2 has occurred.
The system cannot find the file specified.
The resolution, for those who need this, is that the manual indicates the incorrect default path for mongod.exe, which should be in the bin directory
C:\mongodb\bin\mongod.exe
Thus, whereas this is a question, I have also solved this for the benefit of others who may have this problem.
Also, by default, MongoDB will install in C:\Program Files in Windows, and you should use the custom install to put it into C:\mongodb.
It can be possible that you already have a service named "MongoDB" before your installation and thus it is not successfully installed.
try to remove the previous one using this:
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --remove
and then you can try install the service again and fire the net start MongoDB command. It should work now.
I have faced this problem.And I solved as below.
1) Create this folders
C:\data\db
C:\data\log
2)Run CMD as administrator
C:\Windows\System32\cmd.exe
3)If you've installed service , write below to cmd to remove
C:\Program Files\MongoDB\Server\3.6\bin> mongod.exe --remove
4) This is important , I don't use sc.exe Determine the log and db directory ,and instal service
C:\Program Files\MongoDB\Server\3.6\bin> mongod.exe --logpath c:\data\log\mongod.log --dbpath c:\data\db --directoryperdb --install
5)If success
net start MongoDB
After having installed mongodb in C:\mongodb you just do:
mongod --install --logpath C:\mongodb\logs\mongo.log
The path to the logfile must exist and it must be an absolute Windows path. Then you start the MongoDB service by typing:
net start MongoDB