How can I get or figure out the size of a document stored in Cosmos DB?
Is this something already stored within document?
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.
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']
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With