2017-08-10 1 views
0

Ich verwende DynamoDB lokal und kann Tabelle erstellen und löschen. Ich habe eine Tabelle mit nur einem Schlüssel wie untennode.js: DynamoDB DocumentClient, das leeres Objekt zurückgibt

const tablePromise = dynamodb.listTables({}) 
    .promise() 
    .then((data) => { 
     const exists = data.TableNames 
      .filter(name => { 
       return name === tableNameLogin; 
      }) 
      .length > 0; 
     if (exists) { 
      return Promise.resolve(); 
     } 
     else { 
      const params = { 
       TableName: tableNameLogin, 
       KeySchema: [ 
        { AttributeName: "email", KeyType: "HASH"}, //Partition key 

       ], 
       AttributeDefinitions: [ 
        { AttributeName: "email", AttributeType: "S" }, 
       ], 
       ProvisionedThroughput: { 
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10 
       } 
      }; 
      dynamodb.createTable(params, function(err, data){ 
       if (err) { 
       console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2)); 
       } else { 
       console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2)); 
       } 
      }); 
     } 
    }); 

Jetzt möchte ich doc bei AWS folgenden Beispiel ein Element in der Tabelle einzufügen.

var docClient = new AWS.DynamoDB.DocumentClient(); 
var tableNameLogin = "Login" 
var emailLogin = "[email protected]"; 

var params = { 
    TableName:tableNameLogin, 
    Item:{ 
     "email": emailLogin, 
     "info":{ 
      "password": "08083928" 
     } 
    } 
}; 

docClient.put(params, function(err, data) { 
    if (err) { 
     console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2)); 

    } else { 
     console.log("Added item:", JSON.stringify(data, null, 2)); 
    } 
}); 

Wenn ich den Einsatz Artikel Code ausführen, bekomme ich Added item: {} Warum es Ausgabe ein leeres Objekt? Fügt es tatsächlich etwas ein? Ich schaute in , aber dieses Mal gibt es nichts aus.

Antwort

0

Sie müssen ReturnValues: 'ALL_OLD' zu Ihren Put-Parametern hinzufügen. Es sieht wie folgt aus.

var params = { 
    TableName:tableNameLogin, 
    Item:{ 
     "email": emailLogin, 
     "info":{ 
      "password": "08083928" 
     } 
    }, 
    ReturnValues: 'ALL_OLD' 
}; 

Für weitere Informationen können Sie dieses https://github.com/aws/aws-sdk-js/issues/803

folgen
Verwandte Themen