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

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

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 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

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 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