-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathquery-scan-count.js
36 lines (30 loc) · 1.05 KB
/
query-scan-count.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient({ region: "us-west-2" });
const query = async () => {
const response = await documentClient
.query({
TableName: "Music",
KeyConditionExpression: "#pk = :pk and begins_with(#sk, :sk)",
ExpressionAttributeNames: {
"#pk": "Artist",
"#sk": "SongTitle",
},
ExpressionAttributeValues: {
":pk": "Michael Jackson",
":sk": "A",
},
})
.promise();
console.log(
`This query has scanned ${response.ScannedCount} items and returned ${response.Count} items in total`
);
if (response.LastEvaluatedKey) {
console.log(
`Not all items have been retrieved by this query. At least one another request is required to get all available items. The last evaluated key corresponds to ${JSON.stringify(
response.LastEvaluatedKey
)}`
);
}
console.log(`Query response: ${JSON.stringify(response, null, 2)}`);
};
query().catch((error) => console.error(JSON.stringify(error, null, 2)));