I'm trying to query some data between 2 dates from dynamoDb using dynamoose with nestjs. I have a history table with this schema:
const HistorySchema = new Schema(
{
messageId: {
type: String,
hashKey: true,
},
sendAt: {
type: Date,
rangeKey: true,
index: {
name: 'sendAtIndex',
global: true,
},
},
}
);
And I'm trying to run this query
const condition = new Condition()
.filter('sendAt')
.between(1, new Date().getTime());
const query = await HistoryModel
.query(condition)
.using('sendAtIndex')
.exec();
console.log(query);
Debugging the query gave me this
{
"ExpressionAttributeNames": {
"#qha": "sendAt"
},
"ExpressionAttributeValues": {
":qhv_1": {
"N": "1"
},
":qhv_2": {
"N": "1690365822635"
}
},
"TableName": "histories",
"IndexName": "sendAtIndex",
"KeyConditionExpression": "#qha BETWEEN :qhv_1 AND :qhv_2"
}
And all I'm getting is this error message: Query key condition not supported
Is between condition not supported with Date type? If so which type of data should I use?
You must also specify the partition key for a Query
request.
You must provide the name of the partition key attribute and a single value for that attribute. Query returns all items with that partition key value. Optionally, you can provide a sort key attribute and use a comparison operator to refine the search results.
const condition = new Condition()
.filter('sendAt')
.between(1, new Date().getTime());
const query = await HistoryModel
.query("gsipk").eq("gsipkvalue")
.where(condition)
.using('sendAtIndex')
.exec();
console.log(query);