[MongoDB]: _tmp significance in MongoDB dbpath

What is the significance of _tmp directory is used for in MongoDB and why it gets created?

There are at least two ways from MongoDB to create a _tmp directory.

INITIAL FILE ALLOCATION : –
========================
During the file allocation, a _tmp directory is created and the data files will be created there originally.
After the file allocation, the files are moved to the proper directory. If something goes wrong during the allocation phase, the file will be deleted only if is empty.
At the end of the process, the _tmp directory should be empty unless something went wrong during the allocation phases.

REPAIR DATABASE : –
===============
The _tmp directory used to be created when you run a repair command with an empty backupFiles option and contains a full copy of the database.
You can check the output of the following command to confirm that whether the directory contains a backup or is just the temporary location for the allocated files.

ls -lhR <dbpath>
Should it be automatically removed at some point?

From the file allocator point of view, the directory will be recreated if some new files are allocated.
If the directory contains a backup database it could be removed if the information isn’t needed anymore.

Does it contain any sensitive user data?

Only if the directory contains a backup, in this case those files have all the database information including the database user information.

  • Ask Question