简体   繁体   English

DynamoDB:获取每个数组项的属性

[英]DynamoDB : Getting attributes of every item of array

I'm trying to BatchGetItem with an array of primary keys, but the problem is BatchGetItem want 我正在尝试使用主键数组BatchGetItem,但问题是BatchGetItem想要的

Keys : [ 
 { 'username' : 'username1'} 
 { 'username' : 'username2'}
]

instead of 代替

Keys : [ 'username' : ':someUsernameArray' ]

Here is the part of my Lambda Function (in Node.js) 这是我的Lambda函数的一部分(在Node.js中)

var follower_arr = Array.from(data.Item.followers.values);

var follower_params = {
    RequestItems : {
        USER : { 
            Keys :?,
            ProjectionExpression : "university.#name,full_name,username",
            "ConsistentRead": false,
            "ExpressionAttributeNames": { 
                "#name" : "name" 
             }    
        },
    }
}

docClient.batchGet(follower_params,function(err,data){
    if(err){
        callback(err,null);
    }else{
        callback(null,data);
    }
});

follower_arr value is an array of usernames such as, follower_arr值是一个用户名数组,例如

['jack', 'michael_is_cool', 'mark_me_but', 'brownie_mr_brown']

So how can I get the attributes of all the elements of array which consists of primary keys? 那么如何获得由主键组成的数组的所有元素的属性?

You need to convert the array of usernames into an array of objects as show below. 您需要将用户名数组转换为对象数组,如下所示。 Use the resultant array in your query parameters. 在查询参数中使用结果数组。

follower_arr.forEach(function (ele) {
    keys.push({ username: ele })
}) 

var follower_params = {
    RequestItems : {
        USER : { 
            Keys :keys   
        },
    }
}

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

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