By default data files for MongoDB are all created in a single directory. This directory is defined by the --dbpath variable and defaults to /data/db.
The "directory per DB" option (--directoryperdb) allows for a separate directory for the files of each database.
Uses
The most common use for this option is to enable data to be stored on different physical disks. This is generally accomplished by creating a symbolic link to the appropriate underlying hardware.
Example
The following sample demonstrates the difference in directory structures. The db/ directory is run without "directory per DB", the db2/ directory is run with "directory per DB".
db:
total 417M
-rw------- 1 mongo mongo 64M 2011-04-05 12:50 foo.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:50 foo.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:50 foo.ns
-rw------- 1 mongo mongo 64M 2011-04-05 12:48 test.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:48 test.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:48 test.ns
-rwxr-xr-x 1 mongo mongo 5 2011-04-05 12:47 mongod.lock
db2:
total 16K
drwxr-xr-x 2 mongo mongo 4.0K 2011-04-05 12:50 foo
-rwxr-xr-x 1 mongo mongo 5 2011-04-05 12:47 mongod.lock
drwxr-xr-x 2 mongo mongo 4.0K 2011-04-05 12:48 test
db2/foo:
total 209M
-rw------- 1 mongo mongo 64M 2011-04-05 12:50 foo.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:50 foo.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:50 foo.ns
db2/test:
total 209M
-rw------- 1 mongo mongo 64M 2011-04-05 12:48 test.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:48 test.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:48 test.ns
PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus