# db.collection.totalSize()

* `db.collection.` `totalSize` ()

|     |                                                                                                                              |
| --- | ---------------------------------------------------------------------------------------------------------------------------- |
| 返回： | 集合中数据的总大小(以字节为单位)加上集合中每个索引的大小。 如果压缩了集合数据(即WiredTiger 的默认值)，则返回的大小反映了集合数据的压缩大小。 如果索引使用前缀压缩(即WiredTiger 的默认值)，则返回的大小反映索引的压缩大小。 |

返回的 value 是db.collection.storageSize()和db.collection.totalIndexSize()的总和(以字节为单位)。

译者：李冠飞

校对：


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mongoing.com/can-kao/mongo-shell-methods/collection-methods/db-collection-totalsize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
