[英]Using AWS-SDK for DynamoDB, createSet creates a Map instead of a Set
If you were to create a new item and leave an empty list (ie { a: 'string', b: [] }
in your params, it'll convert this to a List Attribute. What I actually want is a String Set Attribute, or SS.如果您要创建一个新项目并留下一个空列表(即
{ a: 'string', b: [] }
在您的参数中,它会将其转换为列表属性。我真正想要的是一个字符串集属性,或 SS。
I scoured through the documentation more and found createSet and was hopeful this will solve my problem.我仔细阅读了文档并找到了createSet并希望这能解决我的问题。 But unfortunately it created a Map Attribute instead.
但不幸的是,它创建了一个 Map 属性。 Currently, this is how I'm creating it:
目前,这就是我创建它的方式:
const aws = require('aws-sdk');
(async () => {
const docClient = new aws.DynamoDB.DocumentClient();
const params = {
TableName: 'some_table_in_dynamodb',
Item: {
a: 'some string',
b: docClient.createSet([])
}
};
const response = await docClient.put(params).promise();
console.log(response);
})();
I got the solution from playing with the UI on DynamoDB: The list CANNOT be empty, otherwise it'll convert it to a Map attribute.我通过在 DynamoDB 上使用 UI 获得了解决方案:列表不能为空,否则会将其转换为 Map 属性。 to fix this, just add an empty string.
要解决此问题,只需添加一个空字符串。
const aws = require('aws-sdk');
(async () => {
const docClient = new aws.DynamoDB.DocumentClient();
const params = {
TableName: 'some_table_in_dynamodb',
Item: {
a: 'some string',
b: docClient.createSet(['']) // ADD STRING FOR SS ATTRIBUTE
}
};
const response = await docClient.put(params).promise();
console.log(response);
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.