[英]How to get nested items in dynamodb?
I m using node typescript and local dynamodb.我正在使用节点 typescript 和本地 dynamodb。 I'm unable to get a specific nested document.我无法获得特定的嵌套文档。 I m trying to get a post on the basis of id.我正在尝试根据 id 获取帖子。 I m using email as pk.我使用 email 作为 pk。
let params1:any= {
TableName: "userTable",
// Key: {
// email: email
// },
FilterExpression: "#posts[0].#id = :postId",
// KeyConditionExpression: `#postId= :postId`,
ExpressionAttributeNames: {
"#posts": "posts",
"#id": "id",
},
ExpressionAttributeValues: {
":postId": event.body.id
},
}
As per comments.根据评论。
you need to remodel your table design by using composite key structure.您需要使用复合键结构来重塑您的表设计。
composite key = email = hash key, postId = range/sort key
note:- if you are using post-operation to query DB, event.body.id should be req.body.id
.注意:- 如果您使用后操作来查询数据库, event.body.id 应该是req.body.id
。
you can simply use dynamodb get operation to grab single record您可以简单地使用 dynamodb get 操作来获取单个记录
const getRecordParams = {
TableName: tableName,
Key: {
email: req.body.id, // hash key
postId: req.body.postId //range key
},
};
const dynamoDbGetResults = await dynamoDb
.get(getRecordParams)
.promise();
dynamoDbGetResults will have your entire record from which you can extract your desired values. dynamoDbGetResults将包含您的整个记录,您可以从中提取所需的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.