Harpreet Sangar
03/22/2024, 7:42 AM{
"name": "Foods",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "portions",
"type": "object[]"
},
{
"name": "portions.portion_id",
"type": "string[]",
"reference": "Portions.portion_id",
"optional": true
}
],
"enable_nested_fields": true
}
{
"name": "Portions",
"fields": [
{
"name": "portion_id",
"type": "string"
},
{
"name": "quantity",
"type": "int32"
},
{
"name": "unit",
"type": "string"
}
]
}
Indexed these documents:
{
"portion_id": "portion_a",
"quantity": 500,
"unit": "g"
}
{
"portion_id": "portion_b",
"quantity": 1,
"unit": "lt"
}
{
"portion_id": "portion_c",
"quantity": 500,
"unit": "ml"
}
and this food:
{
"name": "Milk",
"portions": [
{
"portion_id": "portion_b",
"count": 3
},
{
"count": 3
},
{
"portion_id": "portion_c",
"count": 1
}
]
}
For
{"collection", "Foods"},
{"q", "*"},
{"include_fields", "$Portions(*:merge)"}
I receive
{
"name": "Milk",
"portions": [
{
"count": 3,
"id": "1",
"portion_id": "portion_b",
"quantity": 1,
"unit": "lt"
},
{
"count": 3
},
{
"count": 1,
"id": "2",
"portion_id": "portion_c",
"quantity": 500,
"unit": "ml"
}
]
}
with :merge
.