Search code examples
amazon-web-servicesamazon-dynamodbdynamodb-queriesdocumentclient

What documentclient.query will return if it cannot find the data based on the ExpressionAttributeValues given?


I am new to AWS and improving a query as below which is a dynamodb table query that will perform search based on the id provided. My question is what the document.query will return if it cannot find the data based on one of the ids array element.

const results = ids.map((id) => 
   await documentClient
                .query({
                  TableName: 'table-name',
                  IndexName: 'by-index-all',
                  ProjectionExpression:'....',
                  ExpressionAttributeValues: {
                    ':id':id,
                  },
                  KeyConditionExpression:
                    'id = :id',
                })
                .promise()
                .catch((e) => {
                  console.log(e);
                });

Solution

  • Query which has no data will simply return an empty response Items: [] with a status code of 200.

    A Query operation always returns a result set. If no matching items are found, the result set will be empty. Queries that do not return results consume the minimum number of read capacity units for that type of read operation.

    src