Search code examples
amazon-dynamodbaws-sdkdynamo-local

How to query nested property on dynamo DB


I have data structure in the following way. I want to retrieve all records which are having subjectName PHYSICS PAPER-I and marksGained 40.

Is it possible to query to such records? are there any other libraries we can use on to achieve this?

{
  "CID": "A1",
  "COL_ID": "HARISHFYSX",
  "district": "ADILABAD",
  "grandresult": "C",
  "grandtotal": "232",
  "stdntname": "JAMES",
  "subjects": [
    {
      "marksGained": "38",
      "outcome": "P",
      "passType": "*",
      "subjectName": "ENGLISH PAPER -I"
    },
    {
      "marksGained": "56",
      "outcome": "P",
      "passType": "*",
      "subjectName": "TELUGU PAPER-I"
    },
    {
      "marksGained": "42",
      "outcome": "P",
      "passType": "*",
      "subjectName": "BOTANY PAPER-I"
    },
    {
      "marksGained": "22",
      "outcome": "P",
      "passType": "*",
      "subjectName": "ZOOLOGY PAPER-I"
    },
    {
      "marksGained": "40",
      "outcome": "P",
      "passType": "*",
      "subjectName": "PHYSICS PAPER-I"
    },
    {
      "marksGained": "34",
      "outcome": "P",
      "passType": null,
      "subjectName": "CHEMISTRY PAPER-I"
    }
  ],
  "ticket": "1534343434",
  "UID": "A1_1534343434"
}

Solution

  • Updated:

    AWS Started supporting queries for nested object with expressions.

    https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Attributes.html

    Outdated: Keeping it for reference.

    You cannot query on a nested object, it will be a scan. Following forum discussed in detail,

    https://forums.aws.amazon.com/thread.jspa?threadID=164470

    Hope it helps.