Where is the MongoDB Data? - mongodb

This is more of a general question about how MongoDB works.
But I've been using MongoDB for a while and everything seems to be working for me. The part that currently confuses me, though, is that when I visit the directory where the MongoDB data is saved (I'm using the default data/db) the directory is empty. The data is being persisted, I'm just confused - why does the directory appears empty on my computer?
I'm on Windows, if that's worth anything.

You can execute :
db.serverCmdLineOpts().parsed.storage.dbPath
from inside the mongo process and find what the dbPath startup parameter show to find where your data is saved
or alternatively check from the config file in windows:
<install directory>/bin/mongod.cfg

dbPath can be confusing.
When you run mongod without --dbpath option or unset it in config file then it defaults to \data\db
However, when you use the default config files which comes along the installation then the dpPath is different (I don't remember by heart which). So you should really check path with db.serverCmdLineOpts() as suggested by R2D2
I know, for Linux the default dbPath is /data/db but the pre-installed config file /etc/mongod.conf has set /var/lib/mongo

Related

Missing mongodb.conf on FreeBSD 10.2

After having installed MongoDB 2.6.12 for FreeBSD 10.2, I need to change some MongoDB configuration parameters but there seems to be a problem.
there is no mongodb.conf file in the directory /etc/
instead, I located a mongodb.conf under usr/local/etc/ but the file is empty!?
I don't get it, what is wrong? MongoDB installation routine did not prompt any errors, hence I was expecting a fully operational mongodb.conf under /etc/
How am I supposed to change the MongoDB configuration now? Simply add the desired entries to the existing file under usr/local/etc/?
The correct location is /usr/local/etc/mongodb.conf, and the file is supposed to be empty. All you need is to add something like dbpath=/usr/data/db (or wherever you have created the directory to host your database) to be able to start the server.

MongoDB data not stored in /data/db, although it is saving data... but where?

I'm completely new to MongoDB - I've installed all the programs and set it up so that I run mongod.exe and then mongo.exe. I created a new database called 'test' and inserted some data. However, I can't see any files being created in the /data/db directory. The data is definitely being stored somewhere, and when I closed down all the cmd boxes and started the processes again, the data I initially pushed onto the DB is still there.
I tried running the command 'db.adminCommand("getCmdLineOpts")' which apparently should show my DB Path, but it doesn't:
Can anyone offer some insight on this? Thanks :)
For using mongod.exe without parameters default is C:\data\db. Check start up parameters if you run server as service.
You can run this command to retrieve the dbpath if you in a Linux environment:
grep dbpath /etc/mongod.conf
db.adminCommand("getCmdLineOpts") is not running the db path as it was not specified a a command line parameter when the mongod process was started. It seems the db path is configured in the mongod.conf configuration file and the above command should return it.

MongoDB data storing

maybe is a silly question but I am really wondering where is going to be stored the whole data? If I am looking for this /data/db there is no folder called like this in my root folder on MacOS. Can anyone explain to me how is this work?
Open your Database configuration file.
Look dbpath variable.
For example
dbpath = /srv/mongodb
You have to either create that directory yourself, or specify a different location with
mongod --dbpath=/path/to/dir/db
I usually create a directory called db in my project directory and use that
mongod --dbpath=/home/tim/project/db

How do I specify a relative db path for storing mongodb's data?

I'd like to use a relative path for mongodb, so that each user has a separate data directory when running mongo.
I've tried setting
dbpath = ~/mongodb_data
in my config file, but for some reason that doesn't seem to work - I'm getting:
ERROR: dbpath (~/mongodb_data) does not exist.
At first I thought it might be a permissions error, but I'm running mongod under a user that has rw to ~/mongodb_data.
Is what I'm trying to do feasible, and, if so, how do I get to doing it?
Hello blueberryfields,
I was able to do that just like that on my windows machine:
mongod --dbpath ..\..\data\db
You can use a symbolic link as well.
But as already mentioned, a update on users start up script is the best manageable solution.
I would specify the full path from root rather than using the tilde. I'm not sure it can use that.
dbpath = /home/yourusername/mongodb_data

Where are the db files? at /var/lib/mongodb I cant find any increase in size. I ran very big loop to create lakhs of objects

I am using UBUNTU, from /etc/mongod.conf, I found that /var/lib/mongdb is the path for data.
I have found some files like collectionname.0, .1, .ns in that directory. but when I run a very big loop(lakhs), I am able to get them back using mongo shell, but that mongodb directory size is not increasing, so there must be someother place where this data is being stored
What is that place?
There is no another place. As indicated by #itsbruce, in Ubuntu it's /var/lib/mongodb.
On a non-packaged installation (on Linux), i.e. without a /etc/mongodb.conf file, the default is /data/db/ (unless otherwise specified).
You can modify the switch "--dbpath" on the command line to designate a different directory for the mongod instance to store its data. Typical locations include: /srv/mongodb, /var/lib/mongodb or /opt/mongodb.
(Windows systems use the \data\db directory.) If you installed using a package management system.
I recommend using the db.collection.stats command as outlined here to monitor the size of your collection as you insert data. The link also explains what each field (in the output) means.
That is the correct data location for MongoDB on Ubuntu. MongoDB pre-allocates filespace. Are you sure you have generated more data than would fit into the initial pre-allocated files? Try blowing away any existing data files and restarting Mongo with the --noprealloc flag. Then add data.