forked from aws-samples/aws-dynamodb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-key-condition-expression-greater.js
49 lines (41 loc) · 1.12 KB
/
query-key-condition-expression-greater.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
37
38
39
40
41
42
43
44
45
46
47
48
49
const AWS = require('aws-sdk');
AWS.config.update({ region: "us-west-2" });
const documentClient = new AWS.DynamoDB.DocumentClient();
const query = async () => {
try {
const q = {
TableName: 'Thread',
IndexName: 'ForumViews-index',
KeyConditionExpression: '#fn = :name AND #views > :views',
ExpressionAttributeNames: {
'#fn': 'ForumName',
'#views': 'Views',
},
ExpressionAttributeValues: {
':name': "Amazon DynamoDB",
':views': 0
},
};
const response = await documentClient.query(q).promise();
if (response.LastEvaluatedKey) {
const message = `
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)}.
`.replace(/\s+/gm, ' ');
console.log(message);
}
return response;
} catch (error) {
throw new Error(JSON.stringify(error, null, 2));
}
};
(async () => {
try {
const data = await query();
console.log("Query succeeded:", JSON.stringify(data, null, 2));
} catch (error) {
console.error(error);
}
})();