简体   繁体   中英

Get document size in Cosmos DB

How can I get or figure out the size of a document stored in Cosmos DB?

Is this something already stored within document?

If you get (or query) a document, you can then look at the headers that come back, specifically x-ms-resource-usage , which will contain a documentsSize attribute (representing a document's size in kb).

In node/javascript, you'd make a call that looks something like:

client.readDocument(docLink, function (err, doc, headers) {
  ...
})

You'd want to look at headers['x-ms-resource-usage'] .

Here is the way how to find the largest document in the collection. I used two queries in Azure's data explorer

  1. To get the size of the largest document SELECT MAX(a.length) FROM ( SELECT LENGTH(ToString(c)) AS length FROM c ) a

  2. To retrieve the body of the largest document (The a.length value should be compared to the length returned from the previous query SELECT TOP 1 ac FROM ( SELECT LENGTH(ToString(c)) AS length, c FROM c ) a WHERE a.length = 382725

Then when running the second query you can peek the Query Stats tab to see the exact size of the document.

Per my experience, all the resources created in azure cosmosdb will automatically generate the following attributes:

_rid

_etag

_ts

_self

id

You could find the meaning of these attributes from here .

In addition , the index strategy also takes up space in your cosmos db.

I search the REST API for Azure Cosmos DB but didn't find the method get the document size directly.

However, the query in cosmosdb consumes RU and RU is related to document size. You could refer to the list mentioned in this article .

Please check the RU when you search documents on portal.

在此处输入图片说明

You could also refer to this thread ,maybe it has some implications for you.

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM