How to define "Map" AttributeType in dynamo db?
Solution 1
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 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.
Solution 2
This is basically the drawback of DynamoDB , vs say MongoDB or couchbase . The other NoSQL Dbs can let you have documents of any shape and index any attribute no matter how deep it is. In DD , you don't have this flexibility - top level attributes which are indexable must be scalar . This is the trade off for speed.
Solution 3
You can look here for attribute definitions, the only allowed values are B, N, S
.
You should use strings to define your map.
Vaibhav Patil
Updated on July 09, 2022Comments
-
Vaibhav Patil almost 2 years
I am new in aws dynamo db. I have read that we can set
M
type of attributeValue in schema of dynamo db.But when I execute the code below
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); });
It keeps throwing error
{"message":"Member must satisfy enum value set: [B, N, S]","code":"ValidationException","time":"2018-02-07T11:20:12.930Z","statusCode":400,"retryable":false}
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.
-
Vaibhav Patil over 6 yearsI understand that to insert data I have to write object in the above format ("M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}) but before that I have to create table and I got error while creating table, that's what my question is.
-
Vaibhav Patil over 6 yearsAgain if I store data like ("M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}) then after scan table the data I got in same format and if I want to fetch "Joe" then I have to write "data.M.Name.S", why I cant save just plain object like {Name: "Joe", Age: "35"}?
-
Purefan almost 5 yearsWhat about defining an attribute in a Map as an index?
-
manojlds about 3 years@Purefan - only scalar types can be in index.