Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collection "total document size" is bigger than database "storage size"

Tags:

mongodb

How come that the storage size of the whole mongo database is smaller than total document size?

Storage size enter image description here

Collection size enter image description here

like image 451
Amio.io Avatar asked Mar 23 '18 09:03

Amio.io


People also ask

Why are MongoDB data files large in size?

This is probably because MongoDB preallocates data and journal files. In the data directory, MongoDB preallocates data files to a particular size, in part to prevent file system fragmentation. MongoDB names the first data file <databasename>. 0 , the next <databasename>.

How many collections can a database have MongoDB?

In general, we recommend limiting collections to 10,000 per replica set. When users begin exceeding 10,000 collections, they typically see decreases in performance. To avoid this anti-pattern, examine your database and remove unnecessary collections.

How does MongoDB define maximum number of documents in collection?

Unless you create a capped collection, there is no limit to the number of documents in a collection. There is a 16MB limit to the size of a document (use gridfs in this situation) and limits in the storage engine for the size of the database and data.


1 Answers

MongoDB's WiredTiger storage engine compresses data and indexes by default, so the database storage size on disk (which includes both collection & index data) is typically smaller than the sum of the uncompressed document sizes and index sizes reported in collection stats.

The ratio of storage to uncompressed data size will vary depending on factors such as how compressible your data is, the number and type of indexes you create, whether you have deleted a significant number of documents (creating free space which is available for reuse), and any configuration changes from the default server or collection options.

In your example, you have a total of about 273.5 MB of data & indexes in this database using 70.9 MB of disk storage.

like image 92
Stennie Avatar answered Oct 27 '22 01:10

Stennie