在nodejs中的dynamodb中进行扫描的recursion函数

所以我需要一个nodejs中的recursion函数来replace这个函数调用:

docClient.scan(params, callback)

http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.04.html

这是执行扫描的recursion代码,直到LastEvaluatedKey可用。

 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); } } }