2016-11-25 2 views

Antwort

4

Hier ist die rekursive Code die auszuführen scannen, bis LastEvaluatedKey verfügbar ist.

var AWS = require("aws-sdk"); 
var creds = new AWS.Credentials('akid', 'secret', 'session'); 

AWS.config.update({ 
    region: "us-west-2", 
    endpoint: "http://localhost:8000", 
    credentials : creds 
}); 

var docClient = new AWS.DynamoDB.DocumentClient(); 

var params = { 
    TableName: "Movies" 
}; 

console.log("Scanning Movies table."); 
docClient.scan(params, onScan); 
var count = 0; 

function onScan(err, data) { 
    if (err) { 
     console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2)); 
    } else { 
     // print all the movies 
     console.log("Scan succeeded."); 
     data.Items.forEach(function(movie) { 
      console.log("Item :", ++count,JSON.stringify(movie)); 
     }); 

     // continue scanning if we have more movies 
     if (typeof data.LastEvaluatedKey != "undefined") { 
      console.log("Scanning for more..."); 
      params.ExclusiveStartKey = data.LastEvaluatedKey; 
      docClient.scan(params, onScan); 
     } 
    } 
} 
+1

Das ist großartig! aber es sollte notwendig sein, Count des Ergebnisses hinzuzufügen, das ist nicht so portabel, weil es protokolliert, aber keinen Wert zurückgibt. – locropulenton

+1

es ist perfekt, danke !! – locropulenton

+0

Das hat super funktioniert! Vielen Dank! :) – asuciu