Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query Ravendb document size

I have a scenario in which I need to find the largest documents in my Ravendb database.

When I select any given document in Ravendb Studio, the size is displayed in the Properties section as circled in red in this screen shot:

document properties

Is there a query I can run that will order documents by this Size property so that I can identity the largest documents?

like image 961
Shawn de Wet Avatar asked Oct 30 '25 00:10

Shawn de Wet


1 Answers

Maybe write a method that calculates your object size, probably using reflection.
Then, create a static Map Index with a field 'size',
and set it with your method that you will provide in the 'additional sources' in the index
See https://ravendb.net/docs/article-page/4.2/Csharp/studio/database/indexes/create-map-index#additional-sources
And then you could query this index and order-by the 'size' field


fyi - you can get a specific document size using the following endpoint:

{yourServerUrl}/databases/{yourDatabaseName}/docs/size?id={yourDocumentId}

Learn about ravenDB rest api in:
https://ravendb.net/docs/article-page/4.2/csharp/client-api/rest-api/rest-api-intro

like image 89
Danielle Avatar answered Nov 02 '25 06:11

Danielle