查看数据库中索引总大小
> db.stats() { "db" : "abce", "collections" : 258, "views" : 0, "objects" : 3869336, "avgObjSize" : 23033.87034752216, "dataSize" : 89125783755, "storageSize" : 49488015360, "indexes" : 489, "indexSize" : 132325376, "totalSize" : 49620340736, "scaleFactor" : 1, "fsUsedSize" : 113261400064, "fsTotalSize" : 214643507200, "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1690778757, 1), "signature" : { "hash" : BinData(0,"ncIYGefuLs7KvMS1Acb99Ya3qF0="), "keyId" : NumberLong("7232354472649818114") } }, "operationTime" : Timestamp(1690778757, 1) }
查看单个集合的索引大小:
> db.getCollection("集合名").totalIndexSize();
查看每个集合的索引大小:
> db.getCollectionNames().map(name => ({totalIndexSize: db.getCollection(name).stats().totalIndexSize, name: name})).sort((a, b) => a.totalIndexSize - b.totalIndexSize).forEach(printjson) { "totalIndexSize" : 8192, "name" : "asset_day.v1" } { "totalIndexSize" : 8192, "name" : "asset_day.v1.__in__" } { "totalIndexSize" : 8192, "name" : "p_day.v1" } { "totalIndexSize" : 8192, "name" : "p_day.v1.__in__" } { "totalIndexSize" : 8192, "name" : "swap_asset_day.v1" } ... { "totalIndexSize" : 786432, "name" : "index.com_daily" } { "totalIndexSize" : 794624, "name" : "style_tvalue.v1" } { "totalIndexSize" : 1634304, "name" : "ret_day.v1" } { "totalIndexSize" : 1740800, "name" : "nav_day.v1" } { "totalIndexSize" : 2670592, "name" : "lag_ret" } { "totalIndexSize" : 17883136, "name" : "pos" } { "totalIndexSize" : 17956864, "name" : "ret" } { "totalIndexSize" : 17956864, "name" : "pre_wt" } { "totalIndexSize" : 18001920, "name" : "otr" } { "totalIndexSize" : 18055168, "name" : "ostatus" } { "totalIndexSize" : 18120704, "name" : "owt" } >
查看指定集合中索引的详细信息
> db.<集合名>.stats().indexSizes { "_id_" : 230862848, "groupId_1_userId_1" : 49971200, "createTime_1" : 180301824, "orderId_1" : 278528, "userId_1" : 50155520 }
查看指定索引的大小
> db.collection.stats({indexDetails: true}).indexSizes.index_name
标签:name,查看,索引,mongodb,db,v1,totalIndexSize,day From: https://www.cnblogs.com/abclife/p/17593196.html