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?
KeyConditionExpressionas a partition key caused an error. Someone raised this issue here, and the solution was to useExpressionAttributeNames. Is it really a bug? As far as the code goes, it has been double checked. The items get queried successfully from the console with same conditions. They are in the table for hours now.