4

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?

Shawn de Wet
  • 5,642
  • 6
  • 57
  • 88

2 Answers2

4

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

Danielle
  • 3,324
  • 2
  • 18
  • 31
1

Index (Map) definition:

from doc in docs
select new {
    doc.BlittableJson.Size
}