我想創建一個表,並希望使用Dynamodb(NodeJs)創建6-7列/屬性。我創建了一個表格,但我無法添加超過2個屬性。我是這個平臺的新手,任何人都可以幫助我在一個表格中創建多個屬性。使用nodejs創建表Dynamodb?
1
A
回答
1
在DynamoDB上,您必須僅爲您的表定義Hash Key
和可選的Sort Key
。其餘的屬性不必定義!你可以推送任何你想要的數據。
查看下面的示例,根據the official docs。
我正在用Hash創建表Movies
:Year
和Sort:Title
。 然後我創建一個電影更多的屬性:
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!");
}
});
});
1
在dynamoDB,當你添加一個項目到數據庫屬性將自動創建。
創建表時,我們只指定主鍵和一個可選的排序鍵。
相關問題
- 1. 使用Hive創建DynamoDB表
- 2. 使用Global Secondary Index創建DynamoDB表
- 3. CloudFormation - 爲DynamoDB創建TTL表創建表
- 4. Dynamodb無法創建表格
- 5. 刪除並創建dynamoDB表
- 6. DynamoDB表的編程創建
- 7. 如何使用NodeJS創建圖表?
- 8. 使用boto在LSI的dynamoDB中創建表使用boto
- 9. 從JSON文件創建dynamoDB表
- 10. 無法在dynamodb-local中創建表 - aws
- 11. 如何在本地使用GlobalSecondaryIndexes在DynamoDB上創建表?
- 12. 如何在dynamoDB中動態地使用Hibernate創建表格
- 13. 使用java代碼獲取在AWS DynamoDb中創建的表
- 14. AWS dynamodb - 連接到我的本地dynamodb並創建表
- 15. 搜索在dynamodb列表中使用的NodeJS
- 16. DynamoDB&NodeJS:從JSON數組搜索表
- 17. DynamoDb Nodejs - 放置和更新表
- 18. dynamodb創建字符串集
- 19. 如何使用socketio集羣創建nodejs?
- 20. 如何使用nodejs創建POST rest api?
- 21. 使用nodejs創建OAuth2服務器
- 22. req.isAuthenticated()總是假,PassportJs + nodeJS + dynamoDb
- 23. 使用boto掃描dynamodb表
- 24. Nodejs流CSV,在postgres中創建表並使用COPY導入從
- 25. 如何使用NodeJS服務器端編程創建圖表
- 26. AWS Beanstalk - 自定義應用程序以創建dynamodb表
- 27. 如何在創建DynamoDB表時指定可用區域?
- 28. 如何使用AWS CLI創建Dynamodb全局二級索引?
- 29. 使用PHP和DynamoDB更新和創建條目
- 30. 使用Cloudformation創建具有複合主鍵的DynamoDB