Couchbase query - Passing values from one (sub)query to another query as an input and fetch values

Viewed 17

In the below 1st JSON, I have to fetch all ‘code’ and ‘List’ where ‘override’ is “Y”. there can be ~100 saleWeekly entities, so ‘yearWeek’ can be list for each code.

{
 “country”: “GBR”,
 “field”: “sale”,
 “source”: “onlineSale”,
 “code”: “86401299”,
 “_class”: “com.company.sale”,
 “value”: {
  “country”: “GBR”,
  “onlineSaleWeekly”: [ 
   {
    “yearWeek”: “201906”,
    “reasonCode”: “01”,
    “override”: “Y”
   },
   {
    “yearWeek”: “201913”,
    “reasonCode”: “02”,
    “override”: “N”
   }
  ]
 }
},
{
 “country”: “GBR”,
 “field”: “sale”,
 “source”: “onlineSale”,
 “code”: “86403421”,
 “_class”: “com.company.sale”,
 “value”: {
  “country”: “GBR”,
  “onlineSaleWeekly”: [
  {
   “yearWeek”: “201907”,
   “reasonCode”: “01”,
   “override”: “Y”
  },
  {
   “yearWeek”: “201942”,
   “reasonCode”: “01”,
   “override”: “N”
  }
 ]
 }
}

whatever the codes I got from the above query, i have to fetch corresponding entities from below JSON files (aboveJSON.code == belowJSON.code). and also under each code entity, I need only the yearWeek that I got from first query. ex: if code 123 has yearweeks 201920, 201921 (from above queries) then from below JSON files, even if i saleWeekly has multiple entities, I need only for 201920, 201921 of the same code. Field I need from below JSON - code, List, List, List

{
 “country”: “GBR”,
 “field”: “forecast”,
 “source”: “allSale”,
 “code”: “86401299”,
 “_class”: “com.company.allSale”,
 “value”: {
 “country”: “GBR”,
 “forecastSaleWeekly”: [
  {
   “yearWeek”: “201906”,
   “promoIndicator”: “Y”,
   “number”: 123
  },
  {
   “yearWeek”: “201913”,
   “promoIndicator”: “N”,
   “number”: 234
  }
 ]
 }
},
{
 “country”: “GBR”,
 “field”: “forecast”,
 “source”: “allSale”,
 “code”: “86403421”,
 “_class”: “com.company.allSale”,
 “value”: {
  “country”: “GBR”,
  “forecastSaleWeekly”: [
  {
   “yearWeek”: “201907”,
   “promoIndicator”: “N”,
   “number”: 456
  },
  {
   “yearWeek”: “201942”,
   “promoIndicator”: “Y”,
   “number”: 345
  }
 ]
 }
}

please provide me query for this. there can be ~20k JSON files like this that I have to query.

0 Answers
Related