如何定义“地图”?发电机数据库中的AttributeType? [英] How to define "Map" AttributeType in dynamo db?

查看:121
本文介绍了如何定义“地图”?发电机数据库中的AttributeType?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AWS Dynamo数据库的新手。我已经读到我们可以在dynamo db的架构中设置M类型的attributeValue( https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html )。

I am new in aws dynamo db. I have read that we can set M type of attributeValue in schema of dynamo db ( https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html).

但是当我在下面的代码中执行

But when I execute below code

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:成员必须满足枚举值集:[B ,N,S], code: ValidationException, time: 2018-02-07T11:20:12.930Z, statusCode:400, retryable:false}

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

But the above link says that there is An attribute of type Map available.Can someone explain me how can I achieve Map in dynamo db. Thanks in advance.

推荐答案

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

When you create a dynamodb table, or add an index to it, you can only define the attributes for the indexes. In other words, you can only define the attributes used for a partition key or sort key. like you are doing in your example. But the only attribute types that are valid for keys are S (string), N (number), and B (binary). Maps are not valid attribute types for either partition or sort keys, so you can't use them when defining your table or index.

DynamoDB缺少架构。创建表时,除了索引键的属性外,您没有定义任何其他属性。如果您想在表格中放置地图,只需在放置或更新项目时插入一个地图即可。

DynamoDB is schema-less. You don't define any attributes other than the ones for the index keys at table creation. If you want a map in your table, you simply insert one when you put or update items.

这篇关于如何定义“地图”?发电机数据库中的AttributeType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆