How can I resolve the error below and what is causing "operand type: M" to appear? Despite consulting AWS documentation and searching on stack overflow, I have been unable to find a solution to this issue after spending several hours. My goal is to query an item that is currently active and has a dateSold between a specified start and end date in ISO format. I believe the error "operand type: M" indicates that I am using the map type in my operands such as dateSold, :start, and :end. However, all these operands are simply strings.
The equivalent SQL command would resemble this: SELECT dateSold, profit FROM Items WHERE isActive = 'true' AND dateSold > start AND dateSold < end
Error: "message":"Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: BETWEEN, operand type: M","code":"ValidationException"
Code:
AWS.config.update({ region: "us-east-2" });
const documentClient = AWS.DynamoDB.DocumentClient({ apiVersion: "2012-08-10" });
const options = {
TableName: "Items",
ProjectionExpression: "dateSold, profit",
IndexName: "isActive-dateSold-index",
KeyConditionExpression:
"isActive = :isActive AND dateSold BETWEEN :start AND :end",
ExpressionAttributeValues: {
":start": { S: start.toISOString() },
":end": { S: end.toISOString() },
":isActive": { S: "true" },
},
}
const result = await documentClient
.query(options)
.promise()
Schema:
Table: {
AttributeDefinitions: [
{ AttributeName: "dateSold", AttributeType: "S" },
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: "isActive", AttributeType: "S" },
],
TableName: "Items",
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
GlobalSecondaryIndexes: [
{
IndexName: "isActive-dateSold-index",
KeySchema: [
{ AttributeName: "isActive", KeyType: "HASH" },
{ AttributeName: "dateSold", KeyType: "RANGE" },
],
},
],
},