使用nodejs Dynamodb创build表?
我想创build一个表,并希望使用Dynamodb(NodeJs)创build6-7列/属性。 我创build了一个表,但我不能添加超过2个属性。我是这个平台的新手,任何人都可以帮助我在一个表中创build多个属性。
在DynamoDB上,您必须仅为您的表定义Hash Key
和一个Sort Key
。 其余的属性不必定义! 你可以推送任何你想要的数据。
看看下面的例子,基于官方文档 。
我创build一个表与Movies
哈希: Year
和sorting: Title
。 然后我创build一个更多属性的电影:
var AWS = require("aws-sdk"); AWS.config.update({ region: "us-west-2", endpoint: "http://localhost:8000" }); var client = new AWS.DynamoDB(); var documentClient = new AWS.DynamoDB.DocumentClient(); var tableName = "Movies"; var params = { TableName: tableName, KeySchema: [ { AttributeName: "year", KeyType: "HASH"}, //Partition key { AttributeName: "title", KeyType: "RANGE" } //Sort key ], AttributeDefinitions: [ { AttributeName: "year", AttributeType: "N" }, { AttributeName: "title", AttributeType: "S" } ], ProvisionedThroughput: { ReadCapacityUnits: 10, WriteCapacityUnits: 10 } }; client.createTable(params, function(tableErr, tableData) { if (tableErr) { console.error("Error JSON:", JSON.stringify(tableErr, null, 2)); } else { console.log("Created table successfully!"); } // Adding Batman movie to our collection var params = { TableName: tableName, Item: { "year": 2005, "title": "Batman Begins", "info": { "plot": "A young Bruce Wayne (Christian Bale) travels to the Far East.", "rating": 0 } } }; console.log("Adding a new item..."); documentClient.put(params, function(err, data) { if (err) { console.error("Error JSON:", JSON.stringify(err, null, 2)); } else { console.log("Added item successfully!"); } }); });
在dynamoDB中,将属性添加到数据库时自动创build。
创build表时,我们只指定主键和一个可选的sorting键。
- 在dynamodb Local查询全球二级指数
- 使用Amazon KMSencryption值,使用带有Lambda的DynamoDB存储/检索(NodeJS)
- 带有和/或不带types的AWS DynamoDB数据?
- 使用全局二级索引筛选dynamoDB查询
- 不能更新Dynamo Db表,得到ValidationException
- 使用哈希和范围主键的性能:Dynamodb
- 从S3文件读取JSON并使用带有NodeJS运行时的Lambda将logging插入到dynamoDB中
- 删除dynamodb中的嵌套属性
- DynamoDB,使用AWS Lambda(NodeJS运行时)映射值的dynamicprimefaces更新