why does mongodb not care what my config file is? - mongodb

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.

Related

Change default MongoDB port on Ubuntu Snap installation

I have installed MongoDB using using the following command using snap package manager.
snap install mongo32;
It's working fine. However, I want to change the port & I couldn't find mongodb.conf for this installation. I searched for it in the following locations:
/snap/mongo32
/etc
Recursive grep search gave me the file which contains default port number(32017) for this installation in this file:
/snap/mongo32/2/command-mongod.wrapper
However, this file is read-only, and I assume that it is not a good idea to make changes to a read-only file. Please advice how should I change the default port for mongo32 snap installation. Thanks.
You can see in the snapcraft manifest file here that the default port number is hardcoded:
mongod:
command: bin/run.sh mongod --port=32017 --smallfiles --noprealloc
The mongo snaps follow the convention mongoNN where NN is the port number NN017 (e.g. mongo33 will use the port 33017)

Need to launch mongod using launchctl

I have installed MongoDB using manual option.
When I fire mongod it will take parameters from somewhere else specially for dbPath.
I want to have my own dbPath without specifying it with --dbPath each time.
So I found option to provide mongod.conf file and call mongod --config option but still I need to pass path of .conf file.
My ultimate goal is to just launch mongod as service and it will read config file from path I configured. For this I tried LaunchAgent and LaunchDaemon with no luck. What I thought is that if I can configure LaunchAgent or Daemon then I will provide path to mongod of bin directory of MongoDB folder and provide --config and path for .conf file as argument and then I need to just launch mongod using launchctl with name mongod and it will start mongod --config <.conf file path>.
But I am not able to do so. I read nearly 15-16 posts on LaunchAgent and Daemon but did not get solution my problem. I tried to do so with making mongod.plist file at various places like /Library/LaunchDaemon, /Library/LaunchAgent and ~/Library/LaunchDaemon but I always get error "Path had bad ownership/permissions". I tried chown and chgrp but no luck.
I hope you got my point. I really need complete solution to achieve my goal.
Do you use linux or windows?
This is the default location of mongodb.conf in linux:
/etc/mongodb.conf
You can simply edit it with your parameters, and start the service using:
sudo service mongodb restart
If you are using windows, it depends on the version of MongoDB you are using, but check in:
C:\Program Files\MongoDB\Server\3.4\...
For the same file.

Are the changes done by db command in MongoDB permanent and how?

Are the changes done using the shell in mongodb permanent ?
And how MongoDb detects the config file?
I am stuck in setting Slow query logs in MongoDb.
We have a command db.setProfilingLevel() to set profiling level.
But how can we set profiling for all databases and how to set it via Config file?
How mongodb remember this change after restart?
Yes, Changes made to data in MongoDB shell are permanent but for configuration parameters, they will last only till next restart of instance if they are not specified in config file.
MongoDB runs with default values if config file is not specified.
You can specify config file as,
mongod --config /etc/mongod.conf
or
mongod --f /etc/mongod.conf
and for profiling you can provide parameters from command line or in config file like,
From command line,
mongod --slowms <value in milliseconds for slow queries>
or
mongod --profile <0/1/2>
In config file,
profile = <0/1/2>
slowms = <value>
logpath = <path>

Is it possible to install mongodb without root privilages?

How can I install mongodb on a Linux server without root privileges? is this possible? What would the steps be? Is there a way to configure mongo to not use /data/db?
You may download the binaries from MongoDB website.
There are a lot of options for the command mongod to change the default behavior, one of these is:
--dbpath arg directory for datafiles
Based on comments:
But it is preferable to specify all configurations in a configuration file and just invoke mongod with:
--config filename

How do I force save the dbpath parameter?

I'm just starting out with developing with Mongodb locally and following the tutorials.
I want to use 1 path for all my development.
In the Mongodb documentation it says:
Create a data directory
By default MongoDB will store data in
/data/db, but it won't automatically
create that directory. To create it,
do:
$ mkdir -p /data/db
You can also tell
MongoDB to use a different data
directory, with the --dbpath option.
I want to use one path for all my dbpaths so that I know where they all are and not get confused.
The path I want to use is:
sudo mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
The mongodb.conf file I have is set up as thus:
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /Applications/XAMPP/xamppfiles/var/mongodb
# Only accept local connections
bind_ip = 127.0.0.1
However, I have noticed that I have to keep typing this config path in every time I want to run Mongo.
How do I make it so that Mongodb save the dbpath, or the path to the config without me having to type it out every time?
Thanks.
You can create a startup script, like a bash/cshc script. You must specify those options when starting up.
Make a bash script that runs the commands you want.
Make a file called startMongo.sh
#! /bin/bash
mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
Run command
sudo startMongo.sh