MongoDB YAML "Unrecognized option: security" - mongodb

I am running Mongo DB version 2.6 on Windows Server 2012. I am having trouble setting up the YAML config file for for security and authorization. When I have the below config file I only receive an error saying "Unrecognized option: security". What is wrong with my config?
mongod_test.conf:
security:
authorization: enabled
authenticationMechanisms: MONGODB-CR
storage:
dbPath: F:\MongoData
Command line:
mongod.exe --config mongod_test.conf
I've added spaces back to my file and that fixes part of the problem. With the updated config from above the current error I am getting is:
c:\MongoDBFolder\bin>mongod.exe --config mongod_test.conf
Unrecognized option: security.authenticationMechanisms
try 'mongod.exe --help' for more information

Can't speak for your exact config, but Yaml requires colon+space to separate the keys and values, otherwise you'll get parse errors;
security:
authorization: enabled
authenticationMechanisms: MONGODB-CR
storage:
dbPath: F:\MongoData

The error:
Unrecognized option: security.authenticationMechanisms
is because authenticationMechanisms is not part of the "security" configuration.
As per the documentation:
http://docs.mongodb.org/manual/reference/configuration-options/#security
However, authenticationMechanisms is an option for "setParameter", as per this documentation:
http://docs.mongodb.org/manual/reference/parameters/#param.authenticationMechanisms
I find the documentation convoluted and confusing, but I've not found anything to contradict this, yet.
So, given the above, I think you should be looking at the following:
security:
authorization: enabled
setParameter:
authenticationMechanisms: MONGODB-CR
storage:
dbPath: "F:\MongoData"

Can you ensure there is a space after ":" for the key-value pair lines and also enclose the string values like dbPath value in quotes.

I had an extremely similar error when trying to setup SSL, searching for my problem this was the only relevant result, but was not the solution that was required.
I had a problem with the error:
"Unrecognized option: net.ssl.mode"
The issue was the mongodb version. I had installed using brew which does not default to mongodb with ssl support. To fix this the I had to use the --with-openssl flag.
brew install mongodb --with-openssl

Ensure the configuration file uses ASCII encoding. mongod does not support configuration files with non-ASCII encoding, including UTF-8.

Also make sure your header isn't commented out
security not #security

Related

mongodb.conf not working with YAML syntax

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

MongoDB "Automatically disabling TLS 1.0, to force-enable TLS 1.0"

I'm following this (https://codingthesmartway.com/the-mern-stack-tutorial-building-a-react-crud-application-from-start-to-finish-part-2/) tutorial, and when I reach the part when I type "mongod" into the terminal, I end up with this holy hot mess in my command line. What's gone wrong?
If you do not specify a location for the data files, MongoDB will store its data by default in the \data\db folder of the current drive C:. If the folder does not exist, it will fail with this error. Either create the C:\data\db folder or specify a different location for the data files with the --dbpath option.
The TLS 1.0 disabled warning is not causing any issues. It is just notifying you that TLS 1.0 is disabled by default (TLS 1.0 is considered insecure for encrypted connections), so by default MongoDB only supports TLS 1.1 and newer. This is important only if you're enabling SSL connections to your database.
After installing MongoDB, setup the environment variable of mongodb.
or make a data/db in your C: drive.
if all these are not woking then install mongodb compass and follow the below steps:
1# In start menu type services and open it
2# look for mongodb and start it manually
3# now to check mongod server is running or not go to c:/prografiles/mongodb/4.4/bin/ (where you install your mongodb compass) and open terminal and type mongo > show dbs command show all the databases.
images links for better understanding:
https://drive.google.com/drive/folders/1CLwjXCZ8q6JKwfBXZT9byC_KHmtAjP6E?usp=sharing
I had the same issue with my Ubuntu machine. I found the solution by restarting the MongoDB; use the following commands to restart:-
sudo systemctl stop mongod
sudo systemctl restart mongod
You can also check it in How to install MongoDB on Ubuntu
c:\data\db\ is not found so create it .the same error occurred in my terminal and it was saying that E:\data\db\ is not found and then I created it in my E drive and the problem got solved.
same huge mess for me,
this command will help.
./mongod.exe --config ./mongod.cfg --auth
try to run mongodb with parameter --dbpath /usr/local/mongodb-data if you using mac m1

MongoDB "Unrecognized option: net.ssl.PEMKeyFile"

I'm using MongoDB v3.0.0 with the following configuration file:
storage:
dbPath: "/home/vagrant/backend/mongodata"
engine: wiredTiger
systemLog:
destination: file
path: "/home/vagrant/backend/log/mongo.log"
logAppend: true
net:
port: 27017
# Enable the HTTP interface (Defaults to port 28017).
http:
enabled: false
ssl:
mode: requireSSL
PEMKeyFile: /home/vagrant/backend/keys/privKeys.pem
security:
authorization: 'enabled'
But when I start it up, I get the following error:
Unrecognized option: net.ssl.PEMKeyFile
try '/home/vagrant/backend/mongo/bin/mongod --help' for more information
It looks like I have it set up pretty much exactly like they recommend in the docs: https://docs.mongodb.com/manual/tutorial/configure-ssl/ . The docs say this is new in mongo 3.0, so it should support this option. It does say certain distributions still don't support it (bizarrely), so I should include that I installed mongo via this: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.0.tgz . The closest info I could find is the MongoDB Download Center saying version 3.0.14 for linux "has been compiled with SSL enabled and dynamically linked. This requires that SSL libraries be installed seperately. See here for more information on installing OpenSSL."
Any idea what might be going wrong here?
For me its looks like spacing issue in configuration you may need to check the spacing only two spaces are allowed with list members ssl become underneath of net so when declaring ssl ensure the spaces
here are my working configurations.
net:
port: 28017
bindIp: 127.0.0.1
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb/mongodb-server.pem
CAFile: /etc/ssl/mongodb/mongodb-client.pem
PEMKeyPassword: abc123+
Since MongoDB v3.0.x most MongoDB distributions include support for SSL, but not all. As you have figured out, most likely the distribution that you have does not support SSL.
If you're starting a new MongoDB deployment, I would recommend to install the latest stable release, currently at MongoDB v3.4.x which have more (if not all) distributions supporting SSL. See Release Notes for MongoDB 3.4
Worked for me Mongo version 4.2.8 :
Ignore the message and check the Mongo logs, I found that the path configured for the PEM file was incorrect and should be the fully qualified path. Even after configuring it right, there was this SSL warning that was still present but worked.
ssl:
mode: requireSSL
PEMKeyFile: /data/users/mongodb/mongodb.pem
PEMKeyPassword: YOUR_PASS

MongoDB ignoring dbPath in config file

I'm setting up a fresh centOS 7 install following these instructions.
https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-red-hat/
Using systemctl start mongod I get a error saying /data/dbs does not exist (which it doesn't). If I run
sudo mongod -f /etc/mongod.conf
Everything seems to work. I don't really want to edit the init script if I can avoid it, but is there any way to fix this?
If you are installing using yum in CentOS7 by using the repository file described in Configure MongoDB v3.0 yum, the MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb by default, and runs using the mongod user account.
the default config should contain a section similar to:
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
Make sure whether there's no modification made to the content of your /etc/mongod.conf.
So the solution has ended up just being a new service which calls mongod with the parameters I want. I've disabled the default mongod service
systemctl disable mongod
Added my service file to /etc/systemd/system and enabled it
systemctl enable my-mongod
It works well enough and shouldn't be broken by updates as they come down. The only thing that threw me for a bit is that the service had to be of type forking for it to work.

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.