Unable to change dbpath in MongoDB using command line - mongodb

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

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

How to set mongo db path permanently

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

How can I access copied mongodb folder

I just got copied database folder(literally copy and paste) of mongodb.
Actually, I'm beginner of mongodb and have a lot of problem to access copied database.
Could you give me any advice?
To start the database with the new directory - you can do the following:
Change dbpath in config: link, then restart mongod service
Run single mongod instance like "mongod --dbpath /data/db".
If you use WireTiger engine - "mongod --dbpath /data/db --storageEngine wiredTiger"

issue in start mongodb after change dbpath

Hi, Am editing dbpath of running mongodb in 'amazon ubuntu
instance'(have more than 30 GB data), and I attached some volumes I
for data, log, and joural
I followed mongodb-ec2
mount /data , /log and /journal
stop mongodb
edit /etc/mongodb.conf
mongodb.conf
dbpath=/data
copy all files from old dir to new mount volumes.
start mongodb
.
For testing I run a python script,
from pymongo import MongoClient
db = MongoClient().my_testdb
I got the error message,
pymongo.errors.ConnectionFailure: could not connect to
localhost:27017: [Errno 111] Connection refused
So I remove the lock from the /data/mongod.lock.
and run sudo mongod --repair The following error I got
..........
ERROR: dbpath (/data/db/) does not exist
........
My question is, even though I configured dbpath=/data, why it try to look for the path /data/db? how can I resolve it?
When you run mongod --repair you are not using your config file at all, so you will need to pass --dbpath as part of the command, e.g.:
mongod --dbpath /data --repair
Or if you wish to use the config file, run:
mongod -f /etc/mongod.conf --repair

Mongo data base

Can't find my data base path in mongoDB.
I really need to know where my data is stored on my Mac OSX 10.7
And when I change my DBpath it keeps telling me that DBpath is not defined. (I am using homebrew)
Thank you in advance.
By default mongo configurations are stored on the following path.
/etc/mongod.conf
You can find the dbpath in the following file. By default it is :
/data/db or c:\data\db
You can change the dbpath using the following command
mongod --dbpath /data/newpath
You should be able to find the dbpath used by running the following command in the mongo JS shell:
db.serverCmdLineOpts()
Look for a parsed setting for "dbpath".