Reputation: 30298
How can I get or figure out the size of a document stored in Cosmos DB?
Is this something already stored within document?
Upvotes: 16
Views: 13856
Reputation: 261
Here is the way how to find the largest document in the collection. I used two queries in Azure's data explorer
To get the size of the largest document SELECT MAX(a.length) FROM ( SELECT LENGTH(ToString(c)) AS length FROM c ) a
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 a.c 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.
Upvotes: 19
Reputation: 71067
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']
.
Upvotes: 9
Reputation: 23782
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.
Upvotes: 0