How to set mongo db path permanently - mongodb

Is there a way to over-rite the mongodb default db path. Even after editing the storage path in mongod.conf to the custom directory path. Still it looks for /data/db, and not the custom path.
Since every time mongod path needs to be specified for the custom path.
mongod --dbpath /Users/customData
Is there a permanent way to deal this.

You can try to run it as a service, so that you don't need to run this command everytime you want to use it, and it runs it in the path you set it to
Here's how:
the link
from official mongodb website: the link

According to documentation of MongoDB
To run a mongod process as a daemon (i.e. fork), and write its output
to a log file, use the --fork and --logpath options. You must create
the log directory; however, mongod will create the log file if it does
not exist.
The following command starts mongod as a daemon and records log output
to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log

Related

MongoDB isn't saving the dbpath that I assign to it. How can I save the dbpath?

Im setting my dbpath like so:
mongod --dbpath /Users/dylan/development/mongodb/data/db
it then connects to the db and runs fine. But as soon as I exit and try to start mongod again it comes up with this error:
Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option
for some reason it isn't saving the --dbpath
It is a best practice to store all startup parameters in the mongod.conf yaml file
and start the mongod process every time with mongo --config mongodb.conf file or as a service.
example content:
storage:
dbPath: /Users/dylan/development/mongodb/data/db
If you dont specify the dbPath location , the mongod process start with default dbPath location( /data/db ) or if started as service the dbPath found in default config file located in linux at /etc/mongod.conf

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.

Fix mongod install via command line

After installing mongodb on windows, I set up the necessary folders but made a typing mistake when doing the following command:
mongod --directoryperdb --dbpath C:\mondodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install
the folder is named mongodb but i named it mondodb by accident and can't seem to overwrite that, so when I start mongodb by doing net start mongodb I get an error in my log saying C:\mondodb\data\db not found
I tried redoing it like so mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install but it's not working.
how can I redo the mongod thingy?
There are a few different things you could try:
Go into the registry and change the service path: Modifying the "Path to executable" of a windows service. After you modify it, you can go into Services.msc, right-click on the service, go to Properties, then Look at the Path to executable: and make sure that it points to mongodb rather than mondodb.
It involves editing the registry, but service information can be found in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services. Find the service you want to redirect, locate the ImagePath subkey and change that value.
Go into a command prompt (may need to Run as Administrator) and do sc delete mongod <or whatever the service is named> -- can check services.msc for that). Then re-run your command with the correct path.
Alternately, you might try to set it up by taking a config file so that you can just change those options via config file rather than having to modify the service or delete/reinstall the service when you want to change options. I believe the command there is C:\<mongopath>\mongod.exe -f <config file name> --install.

Unable to change dbpath in MongoDB using command line

I started learning mongoDB a couple of days ago. Post installation, I am trying to change the dbpath as follows:
mongod --dbpath C:\myfolder\myproj\data\db
running the above command, I got the below statements in the command line:
Now i typed the below command to check if the dbpath has changed
mongod dbpath
this line still returns:
C:\data\db
I also tried running the below command to change the dbpath (as mentioned in a youtube video https://www.youtube.com/watch?v=pWbMrx5rVBE, but still the dbpath didn't change
mongod --directoryperdb --dbpath c:\myfolder\myproj\data\db
Can someone tell me how can I change my dbpath?
I looked at the stackoverflow question MongoDB not using /etc/mongodb.conf after I changed dbpath and also Unable to change the dbpath in mongodb through mongodb.conf but none of them helped
When you run
mongod --dbpath C:\myfolder\myproj\data\db
You are starting an instance of mongod with it's data directory as C:\myfolder\myproj\data\db
Running a second
mongod dbpath
is effectively starting a new instance of mongod - which, by default, has its dbpath as \data\db
Just run mongod --dbpath C:\myfolder\myproj\data\db as you are, then use mongo to connect to it (or whatever client you're using)
When connecting to that instance, you'll be using the instance that is storing it's data in C:\myfolder\myproj\data\db

How to specify the dbpath in mango configuration file

I have a Grails application with MongoDB as database, each time that I run my app I have to go to Command Prompt and define dbPath otherwise Test connection will fail. In MongoDB documentation I read that dpPath can be specified in configuration file, but I can not figure it out how I am supposed to do it. Please advise.
create mongo.config file..
dbpath=D:\mongodb\your path
logpath=D:\mongodb\log\mongo.log
bind_ip=127.0.0.1
port=3979
then start the mongod as
mongod --config D:\mongodb\mongo.config