mongodb.conf not working with YAML syntax - mongodb

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

Related

waiting until server is ready for connections. forked process: 7754 child process started successfully, parent exiting

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.

How to specify a config file for Mongod process

When running mongod I receive the non-critical error
[HostnameCanonicalizationWorker] Failed to obtain address information for hostname flimflamjims-MacBook-Pro.local: nodename nor servname provided, or not known
This problem is well documented on stack overflow and solutions typically suggest editing /etc/hosts to specify an address of 127.0.0.1. This does indeed resolve the issue however as an alternative I would like to specify a config file.
As per Homebrew's instructions I have tried running mongod --config /usr/local/etc/mongod.conf. After running the command the process hangs with no logs being printed to the terminal.
mongod.conf was created automatically by Homebrew and its contents are:
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
When I remove mongod.conf from /usr/local/var/log/mongodb/ and again run mongod --config /usr/local/etc/mongod.conf I receive the error:
Error reading config file: No such file or directory
try 'mongod --help' for more information`
So it seems that mongod.conf is at least being accessed.
Any help would be much appreciated.
With your configuration the logs will go to the log file mentioned in the systemLog.path. If you remove only the systemLog.path from the config file, it will thrown error as it won't be able to find the path for log file. Because systemLog.destination says log to file, you must specify systemLog.path as well. In case, you want logs be sent to stdout then you need to remove systemLog.destination and systemLog.path both.

MongoDB Config File (Windows + Environment Variables)

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

Configuring MongoDB on Windows

I am trying to set up MongoDB on Windows, and the online docs seem far from accurate.
Under "Configure a Windows Service" part, step 1 mentions to create a config file. Then it mentions to fill in the file with a line in the format logpath="X:\path\mongo.log". However, following the link, the config file is said to be in YAML format, which renders the previous line unreadable in YAML.
I have created a basic mongodb.cfg(.cfg or .conf??) file:
systemLog:
destination: file
path: "P:\\Servers\\MongoDB\\logs\\mongodb.log"
quiet: true
logAppend: true
storage:
dbPath: "P:\\Servers\\MongoDB\\data"
journal:
enabled: true
net:
bindIp: 127.0.0.1
port: 27017
However when I start mongod --config P:\Servers\MongoDB\mongodb.cfg, the service just won't give any output at all, and just hangs.
If I remove the dbPath line, it will just close itself with no message at all.
I have also tried to leave the mongodb.cfg file just like this:
logpath="P:\Servers\MongoDB\logs\mongodb.log"
dbpath="P:\Servers\MongoDB\data"
But execution aborts complaining about any of the 2 paths, even tho they exist. Tried with single backslashes and with escaped backslashes (\\) with no success.
The only way the service works and listens for connections is to manually pass --dbpath only, and ignore any config file and logpath at all. Obviously this is not serious, as I need to keep track of the logs and also might need to change config parameters at some later point.
This is nuts... Am I missing something very basic or this docs are a real mess?
Here is my simple test MongoDB Config file for Windows. Note that I had to have 2 spaces before each property, e.g., path. When I had 3 spaces I got an error at startup.
I start the server with: mongod --config c:\tools\mongodb\db\mongod.cfg
systemLog:
destination: file
path: "C:\\tools\\mongodb\\db\\log\\mongo.log"
logAppend: true
storage:
dbPath: "C:\\tools\\mongodb\\db\\data"
security:
authorization: enabled
Here's an example of a mongodb.config file for Windows.
##store data here
dbpath=C:\mongodb\data\db
##all output go here
logpath=C:\mongodb\data\log\mongo.log
##log read and write operations
diaglog=3
For those who installed via *.msi installer and wondering where is .conf file located. Run 'services.msc' and check properties of mongodb service runnable file.
Bit late but I had the exact same issue today. If you use forward slashes for your paths within the config file it works fine.
systemLog:
destination: file
logAppend: true
path: "e:/mongo_data/3.6/mongo.log"
storage:
dbPath: "e:/mongo_data/3.6/db"
engine: "wiredTiger"
check if you have any file in data\db path. Please remove all those files and try to restart. I exactly used your config file and able to start the service successfully with bindip and port
You can find logs with reasons why it's not working in log file. In your case, read P:\Servers\MongoDB\logs\mongodb.log file.

MongoDB: Setting up Windows Service

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.