[英]Only retrieve specific data from a row in DynamoDB using JavaScript
Using DynamoDb and the "read" function provided here how would I go about only retrieving specific items (eg only firstname, lastname and city) 使用DynamoDb和此处提供的“读取”功能,我将如何只检索特定项目(例如,仅姓氏,姓氏和城市)
I would probably have to add some kind of filter, however i was not able to find anything that I could use. 我可能必须添加某种过滤器,但是我找不到任何可以使用的东西。
This is my table structure (with bpNumber being the primary key): 这是我的表结构(以bpNumber为主键):
Item:{
"salutationCode": "02",
"lastName1": "Berg",
"firstName": "Anne",
"street": "Am Dächle",
"streetNumber": "22/2",
"zipcode": "33425",
"countryCode": "DE",
"city": "Hausen",
"bpNumber": 222,
"dateOfBirth": "1955-07-01",
"attri": [
{
"attri1":"nonono"
},
{
"attri2": "yeayeayea"
}
]
}
and this the "read" method I'm using: 这是我正在使用的“读取”方法:
read(){
var docClient = new AWS.DynamoDB.DocumentClient()
var table = "businessPartnersData";
var bpNumber = 222;
var params = {
TableName: table,
Key:{
"bpNumber": bpNumber
}
};
docClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
}
Thank you for you time! 谢谢您的时间!
You can use ProjectionExpression: 您可以使用ProjectionExpression:
params.ProjectionExpression = "firstname, lastname, city";
This will only return these attributes in the resultset, for all items. 对于所有项目,这只会在结果集中返回这些属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.