Reputation: 3023
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.
Upvotes: 8
Views: 41350
Reputation: 10224
You can look here for attribute definitions, the only allowed values are B, N, S
.
You should use strings to define your map.
Upvotes: 1
Reputation: 29
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.
Upvotes: 2
Reputation: 1778
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.
Upvotes: 32
Reputation: 2281
The AttributeDefinition property type represents an attribute for describing the key schema for a DynamoDB table and indexes. Only two attributes are mandatory when creating a table, a partition key and sort key if available. If you intended to use the manufacturer
key as an index, please note that it is an invalid operation as dynamodb only supports scalar data types.
tl;dr Therefore, when creating the table, you should omit the "non-key/index" attributes, which in your case is the manufacturer
key.
Upvotes: 0
Reputation: 8571
To insert Map type you should format data like below,
"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}
Please find the screenshot from AWS documentation,
In this example, "M" means Map data type, "Name" is the key "S" (string) is the datatype of that key and value is "Joe" and so on
Also, read documentation here
Upvotes: 3