Skip to content

Why DynamoDB Query not Returning any Items in Low-Level Client? #6848

@waleedshkt

Description

@waleedshkt

Discussed in #6847

Originally posted by waleedshkt January 24, 2025
This may sound ridiculous to ask. But on a serious note, I am putting in an item in DynamoDB successfully using PutItemCommand. I confirm it by scanning for items in AWS console.

But on querying it, the QueryCommand is not returning any item (empty array)

Primary key is comprised of _type partition key and uid sort key. The sort key is hash (string)

Here is my code for querying to get al items with specific partition key:

import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";

const client = new DynamoDBClient({...credentials});
const res = await client.send(new QueryCommand({
   TableName: SOME_NAME,
   ScanIndexForward: false,
   KeyConditionExpression: "#_type = :type AND uid > :uid",
   ExpressionAttributeValues: marshall({
      ":type": "apple",
      ":uid": "0"
   }),
   ExpressionAttributeNames: {
      "#_type": "_type"
   },
}));

if(res) {
   return res.items.map(item => unmarshall (item));
}else{
   throw Error("Failed to fetch");
}

The item in dynamodb to query against has primary key: _type = 'apple' and uid = 'dh46dhdj3jdhd738'

What is possibly wrong? Is using an uncommon underscore prefix in partition key causing any breakage on dynamodb side?

Using

@aws-sdk/[email protected]
@aws-sdk/[email protected]
ap-south-1

Update:
I even checked it with ConsistentRead set to true. But the items are just not returning despite being able to do so in console with same query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions