Node.js DynamoDb get item键上的条件数无效
我一直在试图找到这种情况的解释,但没有找到任何解释。 我有两个DynamoDb表,都有两个键索引,一个是散列键,另一个是范围键 在两个键都是字符串的表中,我可以使用如下哈希键查询数据库(使用NodeSDK):Node.js DynamoDb get item键上的条件数无效,node.js,amazon-dynamodb,Node.js,Amazon Dynamodb,我一直在试图找到这种情况的解释,但没有找到任何解释。 我有两个DynamoDb表,都有两个键索引,一个是散列键,另一个是范围键 在两个键都是字符串的表中,我可以使用如下哈希键查询数据库(使用NodeSDK): const参数={ 表名:process.env.DYNAMODB_表, 键:{id:sessionId}, }; const{Item}=wait dynamoDb.get(参数); 但是,另一个表上的相同操作会抛出所提到的关于键上的条件数无效的错误 以下是两个表模式: 这个表定义允许
const参数={
表名:process.env.DYNAMODB_表,
键:{id:sessionId},
};
const{Item}=wait dynamoDb.get(参数);
但是,另一个表上的相同操作会抛出所提到的关于键上的条件数无效的错误
以下是两个表模式:
这个表定义允许我使用上面提到的查询
SessionsDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: userId
AttributeType: S
-
AttributeName: id
AttributeType: S
-
AttributeName: startDate
AttributeType: S
KeySchema:
-
AttributeName: userId
KeyType: HASH
-
AttributeName: id
KeyType: RANGE
LocalSecondaryIndexes:
- IndexName: byDate
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: startDate
KeyType: RANGE
Projection:
NonKeyAttributes:
- endDate
- name
ProjectionType: INCLUDE
BillingMode: PAY_PER_REQUEST
TableName: ${self:provider.environment.DYNAMODB_TABLE}
这不允许我像上面提到的那样进行查询
SessionsTable:
Type: 'AWS::DynamoDB::Table'
TimeToLiveDescription:
AttributeName: expiresAt
Enabled: true
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: expiresAt
AttributeType: N
KeySchema:
-
AttributeName: id
KeyType: HASH
-
AttributeName: expiresAt
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
TableName: ${self:provider.environment.DYNAMODB_TABLE}
我之所以包含整个表定义,是因为我不知道二级索引是否会对这个问题产生影响
必须提供分区键属性的名称和该属性的单个值。查询返回具有该分区键值的所有项。或者,您可以提供排序键属性并使用比较运算符优化搜索结果。
获取(参数,回调)⇒ AWS.请求
通过委托给AWS.DynamoDB.getItem(),返回具有给定主键的项的一组属性。
在SessionTable
id
中为哈希键,在SessionDynamodBtableid
中为范围键。对于SessionDynamodBtable,除了范围键外,还应提供哈希键
键。您的意思是可以按范围键搜索而不包括整个键,但如果按哈希键搜索,则必须包括整个键?您可以按哈希键搜索,请查看您的表,顺序似乎不正确。您的示例查询使用第二个表(SessionsTable)。您可以通过哈希键进行搜索,而不包括整个键,但是如果您通过Rang键进行搜索,则必须包括整个键。(哈希键)我更新了我的示例以澄清这一点,但我的经验与您提到的完全相反。我可以做一个只包含范围键而不包含哈希键的查询。请看