Chandler
Chandler

Reputation: 63

mongodb keeps data in two places

My remote server is ubuntu 14.04 and I have mongodb installed there. But when I tried to restore my DataBase using mongorestore I noticed the disk space in the following two places have reduced significantly.

/var/lib/mongodb

/data/db

Does anyone know why that is?

Upvotes: 3

Views: 238

Answers (2)

VSK
VSK

Reputation: 469

Primarily, I can deduce the question in to two parts:

  1. why did the file system size reduce after mongorestore
  2. why does mongodb store data in two locations?

Answer for first Q:

Mongorestore just collects the data, but the filesystem size can be different than the actual data size. Mogodb is designed to be in that fashion, it will allocate more space than the actual data size in DB. There is a detailed explanation in the mongodb website refer 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 the /data/db directory in default configurations, might be larger than the data set inserted into the database. Consider the following possible causes:

Second Q:

Refer to bsd response, seems a possible case.

Upvotes: 1

bsd
bsd

Reputation: 2727

It seems you have installed mongo with Ubuntu's APT.

If you simply start the mongod server in a terminal with either nohup or simply keep it running in a different terminal, it assumes the default db path as /data/db/ and the default logging directory as /var/log/mongo.

You might have started mongod with a command like

./bin/mongod

which takes the default data and logging directory.

mongorestore works according to the configuration of the mongod server. This is the reason why you see a surge in space consumption of those directories after you run mongorestore.

The correct way to start the mongod server is with the following command

sudo service mongod start

If you don't want to start/stop as a service, you could also instruct the mongod to correctly use the conf file with the following command

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

Your mongod conf file is located at /etc/mongod.conf. Please change the dbpath and logpath accordingly.

Upvotes: 3

Related Questions