Hi,
There are similar topics to this question (for example, How to map array values in one document to another and display in result) that I have looked at, but the syntax on these is pretty tricky. If someone has the time to look at this, it would be greatly appreciated.
I have two documents, a productCatalog and baseOptions. I would like to leave an empty array placeholder for the baseOptions inside the productCatalog document and then fill it in with the baseOptions when retrieving the catalog. It seems that I should be able to accomplish this with, for example, the array_agg, but so far no luck.
Here is the productCatalog document:
{
“documentType”: “productCatalogTest”,
“offerings”: [{
“id”: “1”,
“name”: “consumer”,
“description”: “Consumer”,
“type”: “b2c”,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”,
“lifecycleStatus”: “Active”,
“productPackages”: [{
“id”: “1”,
“name”: “consumer product”,
“description”: “consumer product”,
“version”: “1”,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”,
“lifecycleStatus”: “Active”,
“baseOptions”: “consumerOptionsArrayRef”
}]
}, {
“id”: “2”,
“name”: “business”,
“description”: “Business”,
“type”: “b2b”,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”,
“lifecycleStatus”: “Active”,
“productPackages”: [{
“id”: “1”,
“name”: “business product”,
“description”: “business product”,
“version”: “1”,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”,
“lifecycleStatus”: “Active”,
“baseOptions”: “businessOptionsArrayRef”
}]
}]
}
I would like to join this document’s consumerOptions array into the productCatalog array:
{
“documentType”: “baseOptions”,
“version”: 1,
“consumerOptions”: [{
“id”: “39”,
“value”: “ENABLED”,
“name”: “Base option 1 v1”,
“disabled”: true,
“provisionable”: false,
“billable”: true,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”
}, {
“id”: “40”,
“value”: “ENABLED”,
“name”: “Base option 2 v1”,
“billable”: true,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”
}, {
“id”: “41”,
“value”: “ENABLED”,
“name”: “Base option 3 v1”,
“billable”: false,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”
}, {
“id”: “42”,
“value”: “ENABLED”,
“name”: “Base option 4 v1”,
“billable”: false,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”
}, {
“id”: “43”,
“value”: “DISABLED”,
“name”: “Base option 5 v1”,
“billable”: true,
“startDateTimeInclusive”: “2020-06-30T10:07:23Z”,
“endDateTimeInclusive”: “2025-06-30T10:07:23Z”
}]
}