How to read a single column from Dynamo-Db without using Scan in Node -js?

I have 4.5 million records in my Dynamo Db.

I want to read the identifier of each record as periodic.

I expect something like bias and limitation, like how we can read in Mongo Db.

Are there any suggestions without a scanning method in Node -JS.

I have done enough research, I can only find a scanning method that buffers full records from Dynamo Db and starts scanning records, which is inefficient in performance.

Please give me an offer.

+4
source share
2 answers

, DynamoDB, , .

DynamoDB , ( ), - API Scan.

DynamoDB ( , )

  • ( $$$)

DynamoDB ( , primary, , DB ..), BatchGetItem Query.

, , Scan - , , .

+2

, , ( Scan doc):

  • DynamoDB

  • ProjectionExpression, Scan ,

- 1 , Limit.

, , , MongoDB offset Limit.

node.js SDK.

, , Promise , LastEvaluatedKey.

, :

const performScan = () => new Promise((resolve, reject) => {
    const docClient = new AWS.DynamoDB.DocumentClient();
    let params = {
        TableName:"YOUR_TABLE_NAME",
        ProjectionExpression: "id",
        Limit: 100 // only if you want something else that the default 1MB. 100 means 100 items
    };
    let items = [];

    var scanExecute = cb => {
        docClient.scan(params, (err,result) => {
            if(err) return reject(err);

            items = items.concat(result.Items);
            if(result.LastEvaluatedKey) {
                params.ExclusiveStartKey = result.LastEvaluatedKey;
                return scanExecute();
            } else {
                return err
                    ? reject(err)
                    : resolve(items);
            }
        });
    };
    scanExecute();
});

performScan().then(items => {
    // deal with it
});
+3

Source: https://habr.com/ru/post/1693546/


All Articles