[英]How to scan in DynamoDB without primary sort key with Nodejs
I'm trying to scan in DynamoDB without primary sort key with Nodejs.我正在尝试使用 Nodejs 在没有主排序键的情况下扫描 DynamoDB。 I have the following Table
我有下表
var params = {
AttributeDefinitions: [
{
AttributeName: "barname",
AttributeType: "S"
},
{
AttributeName: "timestamp",
AttributeType: "S"
}
],
KeySchema: [
{
AttributeName: "barname",
KeyType: "HASH"
},
{
AttributeName: "timestamp",
KeyType: "RANGE"
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
TableName: tableName
};
I put with two objects:我放了两个对象:
data1 = {
barname: "paul",
timestamp: new Date().toISOString(),
sync: false,
number : "1234",
}
data2 = {
barname: "john",
timestamp: new Date().toISOString(),
sync: true,
number : "333",
}
How to scan all objects that barname = 'john' and sync = true?如何扫描 barname = 'john' 和 sync = true 的所有对象?
I tried something like that:我尝试过这样的事情:
var params = {
TableName: tableName,
FilterExpression: "sync = :sync and barname = :barname",
ExpressionAttributeValues: {
':barname' : {S: 'john'},
':sync' : {BOOL: true}
},
};
dynamodb.scan(params, function(err, data){ ... }
The scan doesn't find anything:扫描没有发现任何东西:
{ Items: [], Count: 0, ScannedCount: 4 }
{ 项目:[],计数:0,ScannedCount:4 }
But i have 2 objects that match:但我有 2 个匹配的对象:
The error you are getting is because you are using the DynamoDB.DocumentClient
, but you are specifying the full attribute type in the filter expression.您收到的错误是因为您使用的是
DynamoDB.DocumentClient
,但您在过滤器表达式中指定了完整的属性类型。 If you just change the expression to not include the type it should work.如果您只是将表达式更改为不包含它应该工作的类型。 I won't go into why this is probably a bad idea (scanning).
我不会 go 解释为什么这可能是一个坏主意(扫描)。
var params = {
TableName: tableName,
FilterExpression: "sync = :sync and barname = :barname",
ExpressionAttributeValues: {
':barname' : 'john',
':sync' : true
},
};
dynamodb.scan(params, function(err, data){ ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.