Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the data in a MongoDB database stored on disk?

I know that MongoDB accepts and retrieves records as JSON/BSON objects, but how does it actually store these files on disk? Are they stored as a collection of individual *.json files or as one large file? I have a hunch as to the latter, since the MongoDB docs state that it works best on systems with ext4/xfs, which are better at handling large files. Can anyone confirm?

like image 387
Mark LeMoine Avatar asked Nov 08 '10 19:11

Mark LeMoine


People also ask

Where MongoDB data is stored?

The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt.

Is MongoDB a memory or disk?

MongoDB does store all its data on disk so that it can persist it during server restarts. However, it is primarily liking memory. It relies on the Operating System to schedule which bits of its database stay in memory, and which stays on disk.

Does MongoDB persist data on disk?

By default, MongoDB stores its data into the memory to improve the performance. After reaching the criteria, MongoDB flushes data to the disk. Until then, the data is finally persisted.

How does MongoDB store and access data?

In MongoDB, records are stored as documents in compressed BSON files. The documents can be retrieved directly in JSON format, which has many benefits: It is a natural form to store data. It is human-readable.


1 Answers

A given mongo database is broken up into a series of BSON files on disk, with increasing size up to 2GB. BSON is its own format, built specifically for MongoDB.

These slides should answer all of your questions:

http://www.slideshare.net/mdirolf/inside-mongodb-the-internals-of-an-opensource-database

like image 195
brianz Avatar answered Sep 22 '22 06:09

brianz