Variables from values in MongoDB Arrays with variable length

Hi everyone Vikram here. This is my first question ever so super excited to learn and apologies if the syntax is not up to mark, I will improve with time.

  1. Item is an Array ( this doc has only one element)
  2. Adjudication is a nested Array with a variable number of elements(same structure)
  3. I want to create keys out of “adjudication.category.coding.code” without hardcoding as the values will be different with each document but will have the same string length
  4. I tried using $map to apply the same logic to each array element but failed
'item': [{'adjudication': [{'amount': {'code': 'USD',
                                        'system': '4217',
                                        'value': 22.51},
                             'category': {'coding': [{'code': '',
                                                      'system': ''}]},
                             'reason': {'coding': [{'code': 'C',
                                                    'system': ''}]}},
                            {'amount': {'code': 'USD',
                                        'system': '4217',
                                        'value': 0},
                             'category': {'coding': [{'code': '',
                                                      'system': ''}]}}

Output desired

adjudication: {paid_amt: 22.51, discount_amt: 0}

So neither adjudication, category, coding nor code can be hard coded? Are they at least parameters of the query?

And you want the value of the field named value of the amount object within the element? Is amount field name hard coded?

You also want the field name of the label to be the substring paid_amt from the code that has the prefix Is it always ? Is it always the value after the /?