mongodb 如何知道MongoDB集合大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41712939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:53:12  来源:igfitidea点击:

How to know MongoDB collection size?

mongodb

提问by Selva Kumar

db.collection.stats()

db.collection.stats()

Response :

回复 :

    "count" : 20696445,
    "size" : NumberLong("1478263842661"),
    "storageSize" : 334732324864,
    "totalIndexSize" : 676327424,
    "indexSizes" : {
            "_id_" : 377094144,
            "leadID_1" : 128049152,
            "leadID_hashed" : 171184128
    },
    "avgObjSize" : 71425.97884134208

My actual disk size is matched with storageSize. So what is the size and other keys.

我的实际磁盘大小与storageSize匹配。那么什么是大小和其他键。

采纳答案by Stennie

You haven't mentioned the version of MongoDB server you are using but given the sizeof your data is much larger than the storageSizeon disk, I'm assuming you are using the WiredTiger storage enginewhich compresses data and indexesby default. The WiredTiger storage engine was first available as an option in the MongoDB 3.0 production series and became the default storage engine for new deployments in MongoDB 3.2+.

您没有提到您使用的 MongoDB 服务器的版本,但鉴于size您的数据比storageSize磁盘上的大得多,我假设您使用的是WiredTiger 存储引擎,该引擎默认压缩数据和索引。WiredTiger 存储引擎首先作为 MongoDB 3.0 生产系列的一个选项提供,并成为 MongoDB 3.2+ 中新部署的默认存储引擎。

In your example output it looks like you have 1.4TB of uncompressed datawhich is currently occupying 334GB on disk (the storageSizevalue). Storage space used by indexes for this collection is reported separately under indexSizesand summed up as totalIndexSize.

在您的示例输出中,您似乎有 1.4TB 的未压缩数据data,目前在磁盘上占用了 334GB(该storageSize值)。此集合的索引使用的存储空间在 下单独报告indexSizes并汇总为totalIndexSize

The output of collection.stats()will vary depending on your MongoDB server version and configured storage engine, but is generally described in the MongoDB manual as part of the output of the collStatscommandwhich is called by the db.collection.stats()shell helper.

的输出collection.stats()将根据您的 MongoDB 服务器版本和配置的存储引擎而有所不同,但通常在 MongoDB 手册中作为shell 帮助程序调用collStats命令输出的一部分进行描述db.collection.stats()

Note: MongoDB documentationis versioned so you should always make sure you are referencing documentation that matches your release series of MongoDB (i.e. 3.2, 3.4, ...). Default documentation links will point to the current production release.

注意:MongoDB 文档是版本化的,因此您应该始终确保您引用的文档与您的 MongoDB 发布系列(即 3.2、3.4、...)相匹配。默认文档链接将指向当前的生产版本。

回答by gifpif

Refer link

参考链接

collStats.size
The total size in memory of all records in a collection. This value does not include the record header, which is 16 bytes per record, but does include the record's padding. Additionally size does not include the size of any indexes associated with the collection, which the totalIndexSize field reports.

collStats.size
集合中所有记录在内存中的总大小。该值不包括记录头,即每条记录 16 字节,但包括记录的填充。此外,大小不包括与集合相关联的任何索引的大小,totalIndexSize 字段报告了该大小。

The scale argument affects this value.

scale 参数会影响此值。

collStats.storageSize
The total amount of storage allocated to this collection for document storage. The scale argument affects this value.

collStats.storageSize
分配给此集合用于文档存储的总存储量。scale 参数会影响此值。

storageSizedoes not include index size. See totalIndexSizefor index sizing.

storageSize不包括索引大小。请参阅totalIndexSize索引大小。