Cannot start mongodb network service on Windows 10 after changing dbPath of config file - mongodb

I have installed mongodb 4.2 on my Windows 10 PC. I want to change the dbPath from default C:\Program Files\MongoDB\Server\4.2\data to C:\Users\xx\Dropbox\mongodb_data.
I modifed mongod.cfg such that
dbPath: C:\Users\xx\Dropbox\mongodb_data
When I restart Mongodb network service, I encountered the following error;
How can I fix this error?

Try running MongoDB with additional parameter mongod --dbpath <your new path> it will be reading and writing to this new directory. So, if you want to still have the current documents in Mongo, you can move them to the new directory also.

Related

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

Changing MongoDB 3.6 default db path in Windows

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.
.

mongodb looking in wrong directory for data [duplicate]

I got an error about dbpath (/data/db/) does not exist, but /etc/mongodb.conf named it dbpath = /var/lib/mongodb.
So, which is the default dbpath for MongoDB?
The default dbpath for mongodb is /data/db.
There is no default config file, so you will either need to specify this when starting mongod with:
mongod --config /etc/mongodb.conf
.. or use a packaged install of MongoDB (such as for Redhat or Debian/Ubuntu) which will include a config file path in the service definition.
Note: to check the dbpath and command-line options for a running mongod, connect via the mongo shell and run:
db.serverCmdLineOpts()
In particular, if a custom dbpath is set it will be the value of:
db.serverCmdLineOpts().parsed.dbpath // MongoDB 2.4 and older
db.serverCmdLineOpts().parsed.storage.dbPath // MongoDB 2.6+
I have version 2.0.7 installed on Ubuntu and it defaulted to /var/lib/mongodb/ and that is also what was placed into my /etc/mongodb.conf file.
For a Windows machine start the mongod process by specifying the dbpath:
mongod --dbpath \mongodb\data
Reference: Manage mongod Processes
I depends on the version and the distro.
For example the default download pre-2.2 from the MongoDB site uses: /data/db but the Ubuntu install at one point used to use: var/lib/mongodb.
I think these have been standardised now so that 2.2+ will only use data/db whether it comes from direct download on the site or from the repos.
The dbPath in Mongo can be confusing. If you don't specify the dbPath at all (neither as command line parameter nor in mongod.conf file) then it defaults to
/data/db on Linux and macOS
\data\db on Windows (on current drive)
However, the default mongod.conf files which comes along the installation and which is used when you start mongod as a service (e.g. systemctl start mongod) uses these ones:
Platform
Package Manager
Default storage.dbPath
RHEL / CentOS and Amazon
yum
/var/lib/mongo
SUSE
zypper
/var/lib/mongo
Ubuntu and Debian
apt
/var/lib/mongodb
macOS
brew
/usr/local/var/mongodb
Windows
MSI
C:\Program Files\MongoDB\Server\{release}\data\
So, you must carefully check what you are using.
See Run-time Database Configuration
The Windows x64 installer shows the a path in the installer UI/wizard.
You can confirm which path it used later, by opening your mongod.cfg file. My mongod.cfg was located here C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg (change for your version of MongoDB!
When I opened my mongd.cfg I found this line, showing the default db path:
dbPath: C:\Program Files\MongoDB\Server\4.0\data
However, this caused an error when trying to run mongod, which was still expecting to find C:\data\db:
2019-05-05T09:32:36.084-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
You could pass mongod a --dbpath=... parameter. In my case:
mongod --dbpath="C:\Program Files\MongoDB\Server\4.0\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.

How to discover MongoDB's data directory? [duplicate]

I got an error about dbpath (/data/db/) does not exist, but /etc/mongodb.conf named it dbpath = /var/lib/mongodb.
So, which is the default dbpath for MongoDB?
The default dbpath for mongodb is /data/db.
There is no default config file, so you will either need to specify this when starting mongod with:
mongod --config /etc/mongodb.conf
.. or use a packaged install of MongoDB (such as for Redhat or Debian/Ubuntu) which will include a config file path in the service definition.
Note: to check the dbpath and command-line options for a running mongod, connect via the mongo shell and run:
db.serverCmdLineOpts()
In particular, if a custom dbpath is set it will be the value of:
db.serverCmdLineOpts().parsed.dbpath // MongoDB 2.4 and older
db.serverCmdLineOpts().parsed.storage.dbPath // MongoDB 2.6+
I have version 2.0.7 installed on Ubuntu and it defaulted to /var/lib/mongodb/ and that is also what was placed into my /etc/mongodb.conf file.
For a Windows machine start the mongod process by specifying the dbpath:
mongod --dbpath \mongodb\data
Reference: Manage mongod Processes
I depends on the version and the distro.
For example the default download pre-2.2 from the MongoDB site uses: /data/db but the Ubuntu install at one point used to use: var/lib/mongodb.
I think these have been standardised now so that 2.2+ will only use data/db whether it comes from direct download on the site or from the repos.
The dbPath in Mongo can be confusing. If you don't specify the dbPath at all (neither as command line parameter nor in mongod.conf file) then it defaults to
/data/db on Linux and macOS
\data\db on Windows (on current drive)
However, the default mongod.conf files which comes along the installation and which is used when you start mongod as a service (e.g. systemctl start mongod) uses these ones:
Platform
Package Manager
Default storage.dbPath
RHEL / CentOS and Amazon
yum
/var/lib/mongo
SUSE
zypper
/var/lib/mongo
Ubuntu and Debian
apt
/var/lib/mongodb
macOS
brew
/usr/local/var/mongodb
Windows
MSI
C:\Program Files\MongoDB\Server\{release}\data\
So, you must carefully check what you are using.
See Run-time Database Configuration
The Windows x64 installer shows the a path in the installer UI/wizard.
You can confirm which path it used later, by opening your mongod.cfg file. My mongod.cfg was located here C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg (change for your version of MongoDB!
When I opened my mongd.cfg I found this line, showing the default db path:
dbPath: C:\Program Files\MongoDB\Server\4.0\data
However, this caused an error when trying to run mongod, which was still expecting to find C:\data\db:
2019-05-05T09:32:36.084-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
You could pass mongod a --dbpath=... parameter. In my case:
mongod --dbpath="C:\Program Files\MongoDB\Server\4.0\data"