본문 바로가기
error/Server&DB

[DynamoDB] Invalid KeyConditionExpression: Incorrect operand type for operator or function;

by 이쟝 2023. 9. 20.

문제 상황 

DynamoDB에서 데이터를  query로 불러오려고 했는데 오류가 남 

ValidationException: Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: BETWEEN, operand type: M

 

 

해결

변경 전

function getParams(partitionKey, startDate, endDate) {
  const params = {
    TableName: tableName,
    KeyConditionExpression:
      "UDID = :UDID AND TS BETWEEN :FROM_DATE AND :TO_DATE",
    ExpressionAttributeValues: {
      ":UDID": { S: partitionKey },
      ":FROM_DATE": { N: startDate },
      ":TO_DATE": { N: endDate },
    },
  };

  return params;
}

 

변경 후 

function getParams(partitionKey, startDate, endDate) {
  const params = {
    TableName: tableName,
    KeyConditionExpression:
      "UDID = :UDID AND TS BETWEEN :FROM_DATE AND :TO_DATE",
    ExpressionAttributeValues: {
      ":UDID": partitionKey,
      ":FROM_DATE": Number(startDate),
      ":TO_DATE": Number(endDate),
    },
  };

  return params;
}

 

 


https://stackoverflow.com/questions/66192515/invalid-keyconditionexpression-incorrect-operand-type-for-operator-or-function

 

Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: begins_with

I am trying to learn single table design in DynamoDB with direct lambda resolvers. This is my DynamoDB table: I am trying to query all the users by company ID. But I am getting the error in my

stackoverflow.com