I use the below to create a new database in mongo
sudo mkdir -p /data/db2/
When I start mongo e.g.
mongod --port 27019 --dbpath /data/db2 --replSet rtb/test:27017 --rest
Mongo creates a 3 gig file. I am in dev and to reduce the size to e.g. 100 Megs. How to I do that?
MongoDB will pre-allocate data files. when it starts running. By default a new database will contain the following files (where
testis the name of the DB)test.ns(16MB)test.0(16MB)test.1(32MB)As more files are needed, the pattern continues: 64MB, 128MB, 256MB, 1024MB, 2048MB. After 2GB, each new file will be 2GB.
In your case, you are running a replica set. Replica Sets require a database called
local. This database contains theoplogwhich is used replication. Theoplogis a capped collection.The capped collection is a special collection which must be pre-allocated. In your case it is likely defaulting to about 3GB.
You can control the size of the
localdatabase using the--oplogSizeparameter.If you want to keep your local copy small you can also use the
--smallfilesoption which will slow down the speed of pre-allocation.