2016-12-13 6 views
1

テーブルを作成し、Dynamodb(NodeJs)を使用して6-7列/属性を作成したいとします。私はテーブルを作成しましたが、私は2つ以上の属性を追加することができません。私はこのプラットフォームに新しいです、誰も私は1つのテーブルに複数の属性を作成するのに役立ちます。nodejs Dynamodbを使用してテーブルを作成しますか?

答えて

1

DynamoDBでは、Hash KeyとオプションでテーブルにSort Keyを定義する必要があります。残りの属性は定義する必要はありません。任意のデータをプッシュできます。

the official docsに基づいて、以下の例を確認してください。

ハッシュでMoviesテーブルを作成しています。Yearと並べ替え:Titleです。 は、その後、私はより多くの属性でムービーを作成しています:あなたはデシベルに項目を追加するときDynamoDBので

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

は、自動的に作成される属性。

テーブルの作成時に、主キーとオプションのソートキーのみを指定します。

関連する問題