Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the size of an individual index in MongoDB?

Tags:

mongodb

I know I can use db.collection.totalIndexSize() to get the total index size, but I'm interested in seeing the size of an individual index.

Is this supported?

like image 885
Zach Avatar asked Oct 21 '11 15:10

Zach


People also ask

How does MongoDB determine index size?

Learn commands in MongoDB get data size of database and storage size of database using db. stats(). MongoDB get index size and index storage size of a database using db.

What is MongoDB index size?

The length of the index name cannot be longer than 125 characters. A compound index can have maximum 31 fields indexed.

What is single index in MongoDB?

MongoDB provides complete support for indexes on any field in a collection of documents. By default, all collections have an index on the _id field, and applications and users may add additional indexes to support important queries and operations. This document describes ascending/descending indexes on a single field.

How do I find the size of a collection in MongoDB?

collection. totalSize() method is used to reports the total size of a collection, including the size of all documents and all indexes on a collection. Returns: The total size in bytes of the data in the collection plus the size of every index on the collection.


1 Answers

Certainly can. db.collection.stats().indexSizes is an embedded document where each index name is a key and the value is the total index size in bytes :

> db.test.stats() {         "ns" : "test.test",          <snip>         "indexSizes" : {                 "_id_" : 137904592,                 "a_1" : 106925728         },         "ok" : 1 } 
like image 121
Remon van Vliet Avatar answered Oct 05 '22 21:10

Remon van Vliet