MongoDB- shell default configuration - mongodb

Am new to Mongo DB trying to find the conf file to set up default sever to connect when opening the shell.
Am using:
Windows 10 , shellplus-4.2.5 and connecting to Cloud mongo DB with below command
mongo "mongodb+srv://{SERVER}/test" --username admin
I can not see any config file available. How to set default or Configuration that need to be used
db.adminCommand('getCmdLineOpts');
{ "argv" : [ ], "parsed" : { }, "ok" : 1 }

When you are using MongoDB Atlas, you do not need to set up a server. Atlas is the server.
No configuration is needed to connect to Atlas beyond the correct URI, as described in the documentation.

In case you are using MongoDB Atlas, then you Atlas platform does not the access to the configuration file. In Atlas their is default configuration available which is available on all clusters and users cannot make any changes to the configuration file.
However, in case you are using our own hosted MongoDB deployment then you can access the default MongoDB configuration file on the following path:
On Linux, a default /etc/mongod.conf configuration file is included when using a package manager to install MongoDB.
On Windows, a default /bin/mongod.cfg configuration file is included during the installation.
On macOS, a default /usr/local/etc/mongod.conf configuration file is included when installing from MongoDB’s official Homebrew tap.
For more information please refer the documentation : https://docs.mongodb.com/manual/reference/configuration-options/index.html
and it is not mandatory to use the default mongod.conf file on the above mentioned path. You can make your custom configuration file and can run you own hosted deployment with the following command:
mongod -f mongod1.conf
Please ping me in case you need more information

Related

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 installation. service failed to start

Installing MongoDB as a service is failing for me. The install gets to the point where it tries to start the service and then fails:
Service 'MongoDB Server' (MongoDB) failed to start. Verify that you have sufficient privileges to start system services
This in on a freshly updated new install of Windows 2016
Near default MongoDB 4.2 community install.
Install MongodB as a Service
- Run service as Network Service user.
Directories are not default.
Data Directory : C:\Database\Data
Log Directory : C:\Database\Log
I've granted Network Service full permissions on C:\Database
.net framework 4.6 is installed.
Am I the first person to install MongoDB as a service or something?
Hard to believe someone didn't catch this before.
Update:
Installing to the default directories works. Brutal QA. Any fix to this?
Well, in case someone else comes across this...
One solution is to just install to the default directories, then after the install is done, stop the service, change the cfg to point to the directories you want and copy the files over. Then start it up.
Check path of the MongoDB service by runninng Win+R, type services.msc in opened window find MongoDB server double click it. Here what I see when installed MongoDB to custom folder C:\mongodb MongoDB server path
You probably need to install it into default folder or change path to executable in services.
In latter case run Win+R type there regedit.exe go to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB and change ImagePath key.
In my case key was "C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\4.2\bin\mongod.cfg" --service
and I changed it into "C:\mongodb\bin\mongod.exe" --config "C:\mongodb\bin\mongod.cfg" --service
restart

why does mongodb not care what my config file is?

I can tell mongod does not respect its own default config file because when I type 'mongod' in the terminal, i see
MongoDB starting : ... dbpath=/data/db ...
however in my /etc/mongodb.conf i have
storage:
dbPath: /home/ubuntu/data/db
So it appears mongod does not care about what is defined in its own default config file?
(i know i can add --config /etc/mongodb.conf but I don't see why if this config file is by definition the default config file)
Second question, if mongod does not use /etc/mongodb.conf - is there another config somewhere telling it to put the database path do /data/db (so i can change it) - or is /data/db hard-coded in the int main() of the mongod.exe
Third question: if so does this basically mean you have to always specify the path of the config file when starting mongo?
Fourth question: If it is the case that i must manually define the path to the mongodb config file when starting mongo, how would it be possible to both start mongo as a service like:
service start mongodb
and also specify the config file to be used for the service?
ps. i already know about mongod --fork .... but i'm trying to avoid big long inputs and just have a simple server start/stop/status function with one config file that is respected.
thanks
i'm trying to avoid big long inputs and just have a simple server start/stop/status function with one config file that is respected.
If you run MongoDB as an service in Ubuntu, the config path of /etc/mongod.conf is included in the service definition. Starting and stopping MongoDB as a service is the recommended way to run with consistent settings using a standard config location. You do not need to include any extra parameters when starting or stopping the service; any parameters should be set via the config file.
in my /etc/mongodb.conf i have
Note that the expected location is usually /etc/mongod.conf (named to match the corresponding server daemon). An /etc/mongod.conf with defaults for your O/S should be created as part of the installation (assuming you are using packages provided by MongoDB).
If you installed packages from an alternative source such as the Ubuntu Universe repository, it is possible that your service definition is using /etc/mongodb.conf and may have different defaults from the MongoDB documentation.
So it appears mongod does not care about what is defined in its own default config file?
If you start mongod from the command line, default values for mongod options are used. As at MongoDB 4.0 there is no default config file path baked into the server binary, but there is a default dbPath (/data/db on Linux).
There's a relevant feature suggestion you can watch/upvote in the MongoDB Jira issue tracker: SERVER-36150: Improved default config file handling.

Install Mongodb on windows 7 - 64 bit

I am new to mongodb and not getting how to install it since i dint find videos or any helpful resources to achieve the same. Please help me for installing mongodb on windows 7 with the exact steps. I tried downloading recent version of mongodb from the site and its unsuccessful. Thanks in adcance.
Regards,
Vijay
Steps:
Download MongoDB this link link.
Review MongoDB folder.
In MongoDB, it contains only executable files 10 Plus(exe) in the bin folder. This is true, and That are the required files to MongoDB, it's really hard to believe for a developer like me Who eats from a relation database background.
path:- Files under $MongoDB/bin folder
Configuration File
Create a MongoDB config file, it’s just a text file, for example C:\mongodb\mongo.config:
#store data here
dbpath=C:\mongodb\data
\\all output go here
logpath=C:\mongodb\log\mongo.log
\\log read and write operations
diaglog=3
Run MongoDB server
Use mongod.exe --config C:\mongodb\mongo.config to start MongoDB server.
C:\mongodb\bin>mongod --config C:\mongodb\mongo.config
All output going to: C:\mongodb\log\mongo.log
Connect to MongoDB
Uses mongo.exe to connect to the started MongoDB server.
C:\mongodb\bin>mongo
MongoDB shell version: 2.2.3
connecting to: test
//mongodb shell
MongoDB as Windows Service
Add MongoDB as Windows Service, so that MongoDB will start automatically following each system restart.
Install as Windows Service with --install.
C:\mongodb\bin> mongod --config C:\mongodb\mongo.config --install
A Windows service named “MongoDB” is created.
To start MongoDB Service:
net start MongoDB
To stop MongoDB Service
net stop MongoDB
To remove MongoDB Service
C:\mongodb\bin>mongod --remove
Reference Link Install Mongodb
For mongoDB 4.x, I got installation hung up several times in "wait for a few minutes..."
I changed to v3.2.21-1 as recommended from searching the answer from web. It installed very quick and fast as I installed one year ago.
firstly you downloaded mongodb from here : https://www.mongodb.com/download-center?jmp=nav#community
you unzip the folder in your directory example C:\..\MongoDB
you open the command prompt ( demarrer>Invite commande)
you go to your folder where the bin is and you write this on your command prompt : cd c:\..\mongodb\bin
then you have to specifies the directory where you want to put the data, you can create a folder called : MongoData, and you whrite on your command prompt: Mongod --dbpath C:\..\MongoData
Download the version 4.0.22 from here
And follow steps from Use this tutorial to install MongoDB 5.0 Community Edition on Windows using the default installation wizard
All the best!!!
use mongodb-win32-x86_64-2008plus-ssl-3.2.22-signed for Windows7 64 bit

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.