How to query list of maps in DynamoDB table

2.6k Views Asked by At

I have a dynamo db table with InvId (Primary Partition Key) and PgNo (Primary Sort Key). There is an item in the table called Details which is a list of maps and every map has an attribute called ChargeId. How can I query the map having a particular ChargeId? Can someone help me with a solution how can I design the table so that I can pass the InvId and ChargeId to fetch the particular item from the Details list?

{
  "Anytime": 0,
  "Details": [
    {
      "AccNum": "ACCZ4402255319",
      "Amt": 49.67,
      "ChargeId": 1652849999
    },
    {
      "AccNum": "ACCZ4402255319",
      "Amt": 50,
      "ChargeId": 1652849991
    },
    {
      "AccNum": "ACCZ4402255319",
      "Amt": 49.67,
      "ChargeId": 1652849992
    },
    {
      "AccNum": "ACCZ4402255319",
      "Amt": 50,
      "ChargeId": 1652849993
    }
  ],
  "ExpTime": 253402300800,
  "InvId": "305_40225614",
  "PgNo": 1,
  "SubsId": "406890"
}
1

There are 1 best solutions below

0
On

You need to use a filter expression. It won't be index optimized so be careful.

See DynamoDB: How to use a query filter to check for conditions in a MAP for a code sample.