RavenDB RQL to retrieve also related document

Viewed 83

I'm using RavenDB 5.1

I have a parent document

{
   "ddt": "1313",
   "operator": "Dadas",
   "insertAt": "01/02/2021 12:15:47",
   "code": "R2021.001",
   "clientId": "cbaa9024-abf8-4575-8f44-c06bbb3d8a2e",
   "@metadata": {
      "@collection": "repairOrders"
   }
}

and other documents in another collection

{
   "name": "AZM2E",
   "piva": "31137418148",
   "@metadata": {
      "@collection": "clients"
   }
}

with RQL, I need a query that gives me:

{
   "ddt": "1313",
   "operator": "Dadas",
   "insertAt": "01/02/2021 12:15:47",
   "code": "R2021.001",
   "clientId": "cbaa9024-abf8-4575-8f44-c06bbb3d8a2e",
   "client": {
       "name": "AZM2E",
       "piva": "31137418148",
   }
   "@metadata": {
      "@collection": "repairOrders"
   }
}

I need to execute the query via REST API

1 Answers

You can store a document from the clients collection as a related document on a document from the repairOrders collection.

See example & walkthrough in create-related-documents demo
https://demo.ravendb.net/demos/csharp/related-documents/create-related-documents

Then you can query collection repairOrders:

  1. Include the related document in the query

  2. Select/project the related document info in the query result

  3. See example & walkthrough in query-example demo
    https://demo.ravendb.net/demos/csharp/queries/query-example#step-6

To use include with RQL see: https://ravendb.net/docs/article-page/5.1/csharp/indexes/querying/what-is-rql#include

Related