forked from aws-samples/aws-dynamodb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-key-condition-expression-begins-with.js
48 lines (40 loc) · 1.11 KB
/
query-key-condition-expression-begins-with.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
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: 'Reply',
KeyConditionExpression: '#id = :id and begins_with(#dt, :dt)',
ExpressionAttributeNames: {
'#id': 'Id',
'#dt': 'ReplyDateTime',
},
ExpressionAttributeValues: {
':id': "Amazon DynamoDB#DynamoDB Thread 1",
':dt': "2015-09",
},
};
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);
}
})();