Mongodb stores data in two places

My remote server ubuntu 14.04

, and installed there mongodb

. But when I tried to repair mine DataBase

with help mongorestore

, I noticed that the disk space in the following two places was significantly reduced.

/var/lib/mongodb

/data/db

      

Does anyone know why this is?

+3


source to share


2 answers


You seem to have installed mongo with Ubuntu APT.

If you just start the mongod server in a terminal with nohup

or just keep it in another terminal, it assumes the default db path as the default /data/db/

registration directory as /var/log/mongo

.

You may have started mongod

with a command like

./bin/mongod

      

which accepts the default data directory and logging.

mongorestore

works according to the server configuration mongod

. It is for this reason that you see a spike in space consumption by these directories after launch mongorestore

.



The correct way to start the server mongod

is with the following command

sudo service mongod start

      

If you don't want to start / stop as a service, you can also mongod

instruct to use the conf file correctly with the following command

./bin/mongod --config /etc/mongod.conf

      

Conf file mongod

is located in /etc/mongod.conf

. Change dbpath

and logpath

accordingly.

+3


source


First of all, I can bring the question into two parts:

  • why did the filesystem size decrease after mongorestore
  • Why does mongodb store data in two locations?

Answer for the first Q:

Mongorestore only collects data, but the filesystem size may differ from the actual data size. Mogodb is designed in such a way that it will allocate more space than the actual size of the data in the database. For detailed explanation on mongodb website see this section in this link



Why are the files in my data directory larger than the data in my database?

The data files in your data directory, which is / data / db in the default configurations, can be larger than the installed dataset in the database. Consider the following possible causes:

Second Q:

Refer to the answer bsd

seems possible.

+1


source







All Articles