简体   繁体   English

DynamoDB getItem 仅带有 id (aws sdk)

[英]DynamoDB getItem just with the id (aws sdk)

Is there any way to get an element or more elements (with the same id) with just the id ?, without using alsoe the property name ?有没有办法只使用 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);
  }
});

}); });

You left out some important information in your question, but I am guessing that id is your partition key , and name is the sort key .您在问题中遗漏了一些重要信息,但我猜id是您的partition key ,而namesort key

In That case the answer is yes - you can get all the items with the same partition key id , by using a Query request instead of the GetItem request.在这种情况下,答案是肯定的 - 您可以使用Query请求而不是GetItem请求来获取具有相同分区键id的所有项目。

Please read the documentation of how to properly use Query .请阅读有关如何正确使用Query的文档。 In particularly, note that a Query can theoretically return a very long list of items (which have the same id but different name ) so it is paged , ie, you may need to have to call it multiple times (in the appropriate way) to get all these items.特别要注意,理论上Query可以返回一个非常长的项目列表(具有相同的id但不同的name ),因此它是分页的,即,您可能需要多次调用它(以适当的方式)得到所有这些物品。

Short answer: You can pull one item depending how the Primary Key of your table has been defined.简短的回答:您可以根据表的主键的定义方式提取一项。

Longer version: Here is what API documentation for getItem ( here ) says about the Key field:更长的版本:这是 getItem 的 API 文档( 此处)对 Key 字段的说明:

A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve.一个 map 的属性名称到 AttributeValue 对象,表示要检索的项目的主键

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 ONE record based on the primary key. GetItem 根据主键返回 ONE 记录。 Primary key uniquely identifies a record in the Dynamo table.主键唯一标识 Dynamo 表中的一条记录。

To get multiple records, use BatchGetItem and pass multiple Primary Keys for the records you want to pull.要获取多条记录,请使用BatchGetItem并为要提取的记录传递多个主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM