DynamoDB getItem 只是带有 id (aws sdk)
DynamoDB getItem just with the id (aws sdk)
有没有办法得到一个元素或更多元素(具有相同的id) 仅使用 id ?,而不使用 属性 name
?
let params = {
TableName: "TableName",
Key: {
id: { S: req.body.ProjectId },
// name: { S: req.body.name }
},
};
ddb.getItem(params, function (err, data) {
if (err) {
console.log("Error", err);
res.send(err);
} else {
console.log("Success", data);
res.send(data);
}
});
});
您在问题中遗漏了一些重要信息,但我猜测 id
是您的 分区键 ,而 name
是 排序键.
在那种情况下,答案是肯定的 - 您 可以 获取具有相同分区键 id
的所有项目,方法是使用 Query
请求GetItem
请求。
请阅读有关如何正确使用 Query
的文档。特别要注意的是,理论上 Query
可以 return 一个很长的项目列表(具有相同的 id
但不同的 name
)所以它是 paged,即,您可能需要多次调用它(以适当的方式)才能获得所有这些项目。
简答:您可以提取一项,具体取决于您 table 的主键的定义方式。
更长的版本:
以下是 getItem (here) 的 API 文档对键字段的描述:
A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve.
For the primary key, you must provide all of the attributes. For
example, with a simple primary key, you only need to provide a value
for the partition key. For a composite primary key, you must provide
values for both the partition key and the sort key.
GetItem returns 基于主键的一条记录。主键在Dynamo中唯一标识一条记录table.
要获取多条记录,请使用 BatchGetItem 并为要提取的记录传递多个主键。
有没有办法得到一个元素或更多元素(具有相同的id) 仅使用 id ?,而不使用 属性 name
?
let params = {
TableName: "TableName",
Key: {
id: { S: req.body.ProjectId },
// name: { S: req.body.name }
},
};
ddb.getItem(params, function (err, data) {
if (err) {
console.log("Error", err);
res.send(err);
} else {
console.log("Success", data);
res.send(data);
}
});
});
您在问题中遗漏了一些重要信息,但我猜测 id
是您的 分区键 ,而 name
是 排序键.
在那种情况下,答案是肯定的 - 您 可以 获取具有相同分区键 id
的所有项目,方法是使用 Query
请求GetItem
请求。
请阅读有关如何正确使用 Query
的文档。特别要注意的是,理论上 Query
可以 return 一个很长的项目列表(具有相同的 id
但不同的 name
)所以它是 paged,即,您可能需要多次调用它(以适当的方式)才能获得所有这些项目。
简答:您可以提取一项,具体取决于您 table 的主键的定义方式。
更长的版本: 以下是 getItem (here) 的 API 文档对键字段的描述:
A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve.
For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
GetItem returns 基于主键的一条记录。主键在Dynamo中唯一标识一条记录table.
要获取多条记录,请使用 BatchGetItem 并为要提取的记录传递多个主键。