How to configure storage.smallFiles on mongodb - mongodb

I have a CentOS machine where I installed mongodb and I want it to always use storage.smallFiles setting, so I went to /etc and I created a new file /etc/mongodb.conf where I added the following text and I saved:
storage:
smallFiles:
enabled: true
then I typed:
$ mongod --config /etc/mongodb.conf
Unrecognized option: storage.smallFiles.enabled
try 'mongod --help' for more information
I followed documentation on http://docs.mongodb.org/manual/reference/configuration-options/#storage.smallFiles

The configuration for storage option smallFiles is different for different versions of MongoDB. Note that MMAPv1 storage engine is deprecated in MongoDG v4.0 and removed in MongoDB v4.2 - docs.
MongoDB 3.0–4.0 - docs:
storage:
mmapv1:
smallFiles: true
MongoDB 2.6 - docs:
storage:
smallFiles: true
MongoDB 2.4 - docs:
smallfiles = true
You can check that your setting is properly set by calling this command against admin database:
db.runCommand({getCmdLineOpts:1});
You can also specify it directly when starting mongod:
mongod --config /etc/mongodb.conf --smallFiles

If you're a developer, don't have time and is using a VM getting out of space... Just copy, paste and go!
sudo bash -c "echo \"smallfiles=true\" >> /etc/mongodb.conf"
sudo service mongodb restart

If you are using mongodb: 3.0.
You need to set the Option Hierarchy as storage.mmapv1.smallFiles : true
storage:
mmapv1:
smallFiles: true
Take care of the spaces in your yaml file.
Example:
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
mmapv1:
smallFiles: true

If you are getting this error with mongodb 4.2 then it is because some of the options are removed in Mongo DB 4.2
Removed Configuration File Setting Removed Command-line Option
storage.mmapv1.journal.commitIntervalMs
storage.mmapv1.journal.debugFlags mongod --journalOptions
storage.mmapv1.nsSize mongod --nssize
storage.mmapv1.preallocDataFiles mongod --noprealloc
storage.mmapv1.quota.enforced mongod --quota
storage.mmapv1.quota.maxFilesPerDB mongod --quotaFiles
storage.mmapv1.smallFiles mongod --smallfiles
storage.repairPath mongod --repairpath
replication.secondaryIndexPrefetch mongod --replIndexPrefetch
Please refer Mongodb 4.2 Release Notes

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 automate a mongo db command?

Since the sudo mongod command did not work for my macOS version (/ data/db path was not found), I changed the path to /System/Volumes/Data/data/db.
To start mongo I always have to enter sudo mongod --dbpath /System/Volumes/Data/data/db so that the new path is recognized.
Is there a way to design this process so that I only have to enter sudo mongod again?
I'm using the following macOS version: Catalina 10.15.3 with zsh
You should search for config file of MongoDB and check the content of:
storage:
dbPath: <string>
And dbPath must point to the /System/Volumes/Data/data/db
The usual location of config file is /usr/local/etc/mongod.conf

mongodb on Ubuntu 18.04 Bionic systemctl handling of mongod.service / mongodb.service

I had some issues installing mongod.service on a digital ocean droplet with systemctl. It is set up now except that it complains there is something else taking its port, although nothing actually is. The culprit, I suppose is the following: there is a failed service for mongodb (rather than mongod.service) whose error is "file not found". Do I need to set up or remove the missing mongodb.service? I see there is a /lib/systemd/system/mongod.service but there's not a mongodb.service in that directory.
Here is some of the config in /etc/mongod.conf
storage:
dbPath: /data/db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
I also set sudo chown -R mongodb:mongodb /data/db which fixed errors then but now I'm getting /data/db/WiredTiger.turtle: handle-open: open: Permission denied
...Yay mongod is running after sudo chown -R mongodb:mongodb /data/db/WiredTiger.turtle
I suppose that file was generated and missed getting the permissions.
I just read in the documentation: The Linux package init scripts do not expect storage.dbPath to change from the defaults. If you use the Linux packages and change storage.dbPath, you will have to use your own init scripts and disable the built-in scripts. I believe I had originally changed the dbPath...
check if mongodb is running
sudo service mongodb status
if it says inactive, activate using the below command
sudo service mongodb start
I am adding the detail steps to check the MongoDB running on the localhost or not and how to start it.
To check MongoDB running or not type below command on Linux terminal
ps -Aef | grep mongod
After this command, you will properly see the details of mongod running instance with details of process Id and config file loaded by MongoDB.
If not running then check the status as below
sudo service mongod status
Provide the permission to /data/db or change the location and provide the monogdb ownership of that folder as sudo chown -R mongodb:mongodb /data/db Once done then do restart the MongoDB as below
sudo service mongod start
Now check again the status, its working or not. Still facing issue then visit the official MongoDB documentation with proper install guideline Install MongoDB Community Edition on Ubuntu

Mongodb dbpath argument not changing config file [duplicate]

I am working with Mongo DB and I am a newbie to it. I am about to install it on a server specifically for Mongo.
I would like to create 2 instances of it - 1 to support a QA environment, the other to support a Staging Environment.
I am more familiar with SQL Server where I can create multiple instances.
Is it possible to do the same with Mongo DB and if so, how?
The aforementioned answer is not a recommended way to run multiple instances (especially when the servers might be running at the same time) as it will lead to usage of the same config parameters like for example logpath and pidfilepath which in most cases is not what you want.
Please, consider creating dedicated mongod configuration files like mongod-QA.conf and mongod-STAGE.conf. In these files you may want to provide dbpath, logpath folders, bind_ip, port and pidfilepath specific to each mongod instance and that will not affect each other.
After these steps you are good to trigger two instances as follows
mongod --config <path-to>/mongod-QA.conf
mongod --config <path-to>/mongod-STAGE.conf
You can find more details on mongodb docs page
You just need to create another folder(ex: mongodb2) dbpath for the second instance, and run it in a different port(ex: 27018)
mongod --dbpath /usr/local/var/mongodb2 --port 27018
Here is how I start 4 mongod's on the same pc to emulate production environment in development environment.
To start mongod you should use separate config for each mongod. Take 4 configs and start mongods using them:
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-primary1.cfg
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary1.cfg --rest
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary2.cfg
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary3.cfg
Configs look like this:
mongod-primary1.cfg file contents
systemLog:
destination: file
path: c:\net2\primary1-pc\data\log\mongod.log
storage:
dbPath: c:\net2\primary1-pc\data\db
net:
port: 27018
replication:
replSetName: repl1
mongod-secondary1.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary1-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary1-pc\data\db
net:
port: 27019
replication:
replSetName: repl1
mongod-secondary2.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary2-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary2-pc\data\db
net:
port: 27020
replication:
replSetName: repl1
mongod-secondary3.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary3-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary3-pc\data\db
net:
port: 27021
replication:
replSetName: repl1
It's possible - you would give each one its own port to listen on, and its own --dbpath directory to put its files in, but I wouldn't recommend this because they will both be competing for the same resources - RAM, i/o bandwidth, etc.
If you have multiple disks on this server you can place their data files on separate devices but you're still risking your QA instance reducing availability of the production instances, possibly at the worst possible time.
I would put QA instance on a random machine that's doing something unimportant before I would colocate it with my production instance.

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"