I have just started venturing into MongoDB and the world of NoSQL datatabases. Currently testing a Mongo installation on my Windows. In my config file, I wanted to use Mongo related environment variables that I have set up on my system. But on running the command:
$mongod --config $MONGO_HOME\conf\mongod.cfg --install
I get:
Error reading config file: No such file or directory
try 'mongod --help' for more information
How can I make Mongo understand and replace the environment variable with the right directory path? Here is what the config file looks like currently:
systemLog:
destination: file
path: $MONGO_HOME\log
storage:
dbPath: $MONGO_HOME\data\db
Related
I am on a Windows 10 laptop and installed mongodb 4.4 recently. But when I run mongod, I thought it uses the mongodb.cfg file in the bin directory by default, but changing that made no difference and I ended up launching the server with arguments which is displayed when I run mongod --help.Then I realized I can pass a config file with a -f or --config.
But even after passing the default config file, it gave me this error.
Unrecognized option: storage.dbpath
But I had followed the proper YAML syntax which was mentioned here.
I tried removing space, adding and all other ways to get it working, but it kept giving me the same error. I tried going by what this post said, but I couldn't get it to work.
Then I tried the same on another device with Linux mint.
But there, the mongodb.cfg file, in /etc/ folder was not following YAML syntax(in windows, the default mongodb.cfg in bin folder followed YAML syntax).Rather a format similar to what I have seen in a .bashrc file.
So this surprised me and I tried out the same format in windows 10 machine. Something like this --
dbpath=D:\codes\dbs\dbmongo\data
directoryperdb=true
And this time, it worked when I launched mongod using -f flag to mention the cfg file. It worked fine. It took hours for me to find this because I was trying to get it to work with the cfg file with YAML syntax.
This is the default mongod.cfg file in my windows 10 device, which didn't work.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: C:\Program Files\MongoDB\Server\4.4\data
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: C:\Program Files\MongoDB\Server\4.4\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
Here's the format in which it worked
dbpath=D:\codes\dbs\dbmongo\data
directoryperdb=true
logappend=true
logpath=D:\codes\dbs\dbmongo\log\mongod.txt
# network interfaces
#port=27017
bind_ip=127.0.0.1
Here you can see that the format which worked uses the same parameters as given in the mongod --help and not the YAML syntax mentioned in the official website.
I was wondering if anyone else is facing this issue and how/why YAML cfg file is not working as it should.
Your example is not valid YAML syntax and the parameters might be wrong. I think Parameter names are case-sensitive.
It must be like this:
storage:
dbPath: D:\codes\dbs\dbmongo\data
directoryPerDB: true
i tried installing mongodb, after following all the steps as per the website when i ran "mongod" in the terminal/Hyper
i got this error
error code
later i tired with this code
" mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork "
got another error enter image description here
i'm new to this ,
i'm learning course from udmey , plz help me to create and run mongo in my mac
link i used for installing mongo
You can start mongod processes in a variety of ways. In most distributions you can use either systemd or sysinit. These make use of a configuration file, usually located at /etc/mongod.conf. It looks like you downloaded a tarball and are running it manually without systemd or sysinit.
You can also run mongo in a command line mode, like you show with the following options...
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
... but you can also keep the configuration in a config file and refer to it instead...
mongod -f /etc/mongod.conf
An example of a config file having the same command line options you used would look like ...
systemLog:
destination: file
logAppend: true
path: /usr/local/var/log/mongodb/mongo.log
storage:
dbPath: /usr/local/var/mongodb
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /usr/local/var/mongodb/mongod.pid
net:
port: 27017
bindIp: localhost
Assuming you saved the configuration file to /etc/mongod.conf you can call mongo this way...
mongod -f /etc/mongod.conf
A couple of points...
This config file will only accept connections from itself - localhost, because that is what we put in the config file. If you want it to be wide open replace localhost with 0.0.0.0. Secondly, it uses a PID file to track the process. It expects to be able to write the file /usr/local/var/mongodb/mongod.pid with whatever account you execute the program with. Also, it expects the data directory to exist and be writable by the user that executes the program. The log file directory is non-standard. Your original post referred to /usr/local/var/log/mongodb/mongo.log, but the default logging location for mongo is /var/log/mongodb/mongod.log.
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"
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"
I have just installed MongoDB 2.6 and I am trying to run it as a Windows Service on Windows 8, by following the instructions at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/.
Here's my directory structure within the C drive:
MongoDB (MongoDB installation)
bin
Project
DB
Log
mongo.conf
mongod.cfg
The contents of mongo.conf is:
storage:
dbPath: "C:\Project\DB"
And the contents of mongod.cfg is:
logpath="C:\Project\Log\mongo.log"
As directed to in the tutorial, from the command line (in administrator mode) I then type:
"C:\MongoDB\bin\mongod.exe" --config "C:\Project\mongod.cfg" --install
However, I get an error message:
SEVERE: Failed global initialization: FileNotOpen Failed to open ""C:\MongoDB\bin\Project\Log\mongo.log""
Please can somebody explain what I'm doing wrong? I've followed the instructions as dictated in the tutorial (except changed some of the directory names).
I'm also very confused as to the difference between mongo.conf and mongod.cfg...
Thanks!
I was having a similar problem with Mongo 2.6.3. I was trying to set the log path to C:\Users\Public\Public Databases\Mongo\log\mongo.log and the service installer kept responding with Failed to open ""C:\Program Files\MongoDB 2.6 Standard\bin\Users\Public\Public
Databases\Mongo\log\mongo.log"".
It started working for me when I stopped quoting the log path in the config file. (i.e. I changed logpath="C:\Users\Public\Public Databases\Mongo\log\mongo.log" to logpath=C:\Users\Public\Public Databases\Mongo\log\mongo.log).
There is a known issue installing MongoDB 2.6.0 as a Windows service using the --install command - see SERVER-13515. A fix has been committed for the MongoDB 2.6.1 release.
As a workaround,
I've provided instructions on how to install the service manually on that SERVER issue.
The short version is:
open an Administrator cmd prompt
make directories for your database and log files
create a configuration file
create the service definition, similar to:
sc create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
start the MongoDB service
net start MongoDB
For full instructions please refer to SERVER-13515.
I'm also very confused as to the difference between mongo.conf and mongod.cfg
The MongoDB server doesn't care about the name/extension of the file you specify with --config (as long as the file can be read). Your confusion on the format is because the mongo.conf example uses the new YAML config file format supported by MongoDB 2.6+, while mongod.cfg uses the older format supported by 2.6 as well as earlier versions.
I used the older mongod.cfg format in my workaround example, as technically someone could adapt these instructions to manually create a service definition for MongoDB 2.4 as well.
I got the same problem not only when installing as a Windows service but also when running "mongodb.exe" file. I tried to remove double quote (") characters but the error was still there:
2014-08-16T14:14:49.166Z SEVERE: Failed global initialization: FileNotOpen Failed to open "D:\MongoDB\log\mongo.log"
Please note that I was using config file in new YAML format. I had no problem when using the old format. I tried several ways on the new YAML configuration file and finally I found that it doesn't accept the absolute path. Just change to relative path and it works like a charm!
My folder structure is:
MongoDB\
bin\
data\
log\
Here is my YAML configuration file that works on the build MongoDB 2.6.4 - Windows 64 bit version, installed on my Windows 7 - Professional x64:
systemLog:
timeStampFormat: iso8601-utc
destination: file
path: ..\log\mongo.log
quiet: false
logAppend: true
net:
bindIp: 127.0.0.1
port: 27017
storage:
dbPath: ..\data
directoryPerDB: true
journal:
enabled: true
I tried a lot of things, in the end I had to remove config file and pass dbpath and logpath settings directly. Following command worked for me:-
C:>mongod --dbpath d:\mongodb\data --logpath d:\mongodb\logs\mongo.log --instal
l --serviceName MongoDB --serviceDisplayName MongoDB
There is a JIRA on that topic for the last version of MongoDB and a workaround too. A solution is to install a previous version then install the service ans re-use the last version of the driver.
Hope this helps !
#Stennie 's answer, as well as the manual service installation instructions on the mongoDB site were adequate for me. One thing to note though, is that the quoted items in the instructions need double backslashes (\\) in order to work correctly. Probably obvious to most developers, but I had it slip my mind, and the error response was simply that the service fails to start up. Also, be wary of the spaces after the equals signs.
sc.exe create MongoDB binPath= "\"C:\\Program Files\\MongoDB 2.6 Standard\\bin\\mongod.exe\" --service --config=\"C:\\Program Files\\MongoDB 2.6 Standard\\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
Observing your error log, it's passing two "s instead of one. Omit one(edit your config file content and remove "s) and you should be good.
Sometimes when you have error like : "Failed global initialization: FileNotOpen Failed to open .../mongodb.log", if you have log file you can delete it and try again.
Stop MongoDB from Windows Services and then try again. It worked for me!
My previous logpath=c:\programfiles\......
the alternative is logpath="c:\program files\......"
it works
I think the reason is that the system must visit the log file through c:\program files\......, but there comes error when I write logpath=c:\program files\......because there is a space between program and files. Then I add "", and it works. I hope it helps.