zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

如何读取mongodb的数据库文件大小

2023-04-18 14:23:39 时间

如何读取mongodb的数据库文件大小

读取mongodb数据库文件大小的方法:

1、获取mongoDB中数据库的大小命令

use databasename
db.stats()

显示信息如下

> db.stats()
{ "collections" : 3,
 "objects" : 80614,
 "dataSize" : 21069700, 
"storageSize" : 39845376, 
"numExtents" : 9, 
"indexes" : 2, 
"indexSize" : 6012928, 
"ok" : 1
}

其中storage表示的就是数据库的大小,显示出的数字的单位是字节,因此如果需要转换单位为KB需要除以1024  

2. 获取MongoDB中collection

collection中的数据大小

db.collection.dataSize()

为collection分配的空间大小,包括未使用的空间

db.collection.storageSize()

collection中索引数据大小

db.collection.totalIndexSize()

collection中索引+data所占空间

db.collection.totalSize()