如何在dynamo db中定义“Map”AttributeType?

2024-04-26

我是新来的AWS Dynamodb. I 已读过 https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html我们可以设置Mdynamodb 模式中的属性值类型。

但是当我执行下面的代码时

var params = {
    TableName: 'product',
    KeySchema: [
        {
            AttributeName: 'productType',
            KeyType: 'HASH'
        },
         {
            AttributeName: 'manufacturer',
            KeyType: 'SORT'
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'productType',
            AttributeType: 'S'
        },
         {
            AttributeName: 'manufacturer',
            AttributeType: 'M'
        }
    ],
     ProvisionedThroughput: {
        ReadCapacityUnits: 1, 
        WriteCapacityUnits: 1, 
    }

};
dynamodb.createTable(params, function(err, data) {
   console.log(err, data);

});

它不断抛出错误{"message":"Member must satisfy enum value set: [B, N, S]","code":"ValidationException","time":"2018-02-07T11:20:12.930Z","statusCode":400,"retryable":false}

但上面的链接说有一个 Map 类型的属性可用。有人可以解释一下如何在 dynamo db 中实现 Map 吗?


当您创建 dynamodb 表或为其添加索引时,您只能定义索引的属性。换句话说,您只能定义用于分区键或排序键的属性。就像你在你的例子中所做的那样。但对键有效的属性类型仅有 S(字符串)、N(数字)和 B(二进制)。映射对于分区键或排序键都不是有效的属性类型,因此在定义表或索引时不能使用它们。

DynamoDB 是无模式的。除了创建表时索引键的属性之外,您无需定义任何属性。如果您想在表中添加地图,只需在放置或更新项目时插入一张地图即可。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在dynamo db中定义“Map”AttributeType? 的相关文章