How to get the count of element in a node saved in dynamo db using doClient.scan()

194 views Asked by At

In doClient.scan() is there any way to set the count of elements stored in a particular node?

As per the below example i need to add a new node "questionCount" to the below result which should contain the total number of reference_id in node questionList. is there any way other than iterating the result and adding a new node?

Expected Output

   {
  "status": 1,
  "data": [
    {
      "questionList": [
        {
          "reference_id": "0df55215-90de-407a-b077-7017924556d3"
        },
        {
          "reference_id": "0df55215-90de-407a-b077-7017924556d3"
        },
        {
          "reference_id": "0df55215-90de-407a-b077-701997924556d3"
        }
      ],
      "testName": "sample test231s",
      "testId": "2e97e40c-82cb-4126-9f47-b6a93687a59c",
      "questionCount": 3
    }
  ]
}
1

There are 1 answers

0
Alexander Patrikalakis On

As you add questions to questionList with list_append, you could also increment the questionCount attribute with an UpdateExpression SET data.questionList = list_append(data.questionList, :newQuestion), ADD questionCount :one and ExpressionAttributeValues {":newQuestion": {"reference_id": "blah"}, ":one": 1}.