I see that my mongodb server is creating files like this:


for some of my mongod processes stop to 9, but sometime goes up to 13,14,15. and then I have some space problem on my small AWS instance. I don't want to increase size.

I would like to tell mongo(v2.6) to not go over 10 files, but without blocking the mongo while adding new entries. I want oldest data to be removed or space to be removed.

I used this in order to ask mongo to not create more than 10 files.


but then after a while of execution, while inserting I get this error: MongoError: quota exceeded

is there a way to force mongo to reuse the same files or not creating new ones but without generating errors ?


  • If you're using the legacy storage engine, you should be able to limit the number of files - see my answer here on StackOverflow that shows how, using --quotaFiles. (not sure if it applies to WiredTiger storage - I haven't tried). – David Makogon Sep 22 '16 at 18:11

MongoDB will add new files once the old ones fill up. If you set a quota as you mention, then once you are out of space rather than allocating a new file you will get an error. Those are basically your two choices.

You can use smaller increments of space (but a lot more files) by configuring smallFiles, in which case each additional file at max will be 512MB but you will need to allow ~4x more files in your quota. At some point if you keep adding data with a hard limit (unless you know for a fact that you will not exceed the limit) you will hit the same error though.

Reading between the lines what you want to have is better space reuse by the storage engine, which is a topic that has been discussed many times (see my answer on the topic here). You may find better usage with the WiredTiger storage engine, along with the use of compression (see my testing on that here) but disk space usage will fluctuate depending on your usage patterns, and you will want to have some overhead in terms of space even then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.