RQL - Projections of linked documents in an array? #17432
-
How can you project the fields you want to pull from a linked document in an array within the primary document? In an article here, an example is provided in pulling all the Product Names in the each Order (Product Name being a field that exists directly in the Order document):
which resulted in the query returning an array of only those names: {
"ProductNames": [
"Ikura",
"Gorgonzola Telino",
"Geitost",
"Boston Crab Meat",
"Lakkalikööri"
],
"OrderedAt": "1996-08-05T00:00:00.0000000",
"ShipTo.City": "Cunewalde",
"@metadata": {
"@flags": "HasRevisions",
"@id": "orders/26-A",
"@last-modified": "2018-02-28T11:21:24.1689975Z",
"@change-vector": "A:275-ZzT6GeIVUkewYXBKQ6vJ9g",
"@projection": true,
"@index-score": 1
}
} However, lets say you want to return some information from within the Product document itself. This query works to pull back the Product document:
And will return something like: {
"OrderedAt": "1996-07-04T00:00:00.0000000",
"Freight": 32.38,
"Product": [
{
"Name": "Queso Cabrales",
"Supplier": "suppliers/5-A",
"Category": "categories/4-A",
"QuantityPerUnit": "1 kg pkg.",
"PricePerUnit": 21,
"UnitsInStock": 5,
"UnitsOnOrder": 718,
"Discontinued": false,
"ReorderLevel": 30,
"@metadata": {
"@collection": "Products",
"@counters": [
"⭐",
"⭐⭐",
"⭐⭐⭐",
"⭐⭐⭐⭐",
"⭐⭐⭐⭐⭐"
],
"@timeseries": [
"INC:Views"
],
"@id": "products/11-A"
}
},
...
]
} Using an array index will allow you to pull back the field you want for that specific Product:
Result: {
"OrderedAt": "1996-07-04T00:00:00.0000000",
"Freight": 32.38,
"Product": "Queso Cabrales",
"@metadata": {
"@id": "orders/1-A",
"@last-modified": "2018-07-27T12:11:53.0447651Z",
"@change-vector": "A:81-x863iZJD70mi2zJ6vSEiqw",
"@projection": true,
"@index-score": 0
}
} But I want to retrieve something from each Product document. Any of the approaches I have tried have either returned an error or null Have tried Product: p[].Name (error) Product: [p.Name] (array containing null) Or is this not possible in RQL and you have to use a programming language and perform a loop? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use this, no?
|
Beta Was this translation helpful? Give feedback.
You can use this, no?