Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DyanamoDB SCAN with nested attribute

Can I scan DynamoDB by 'order.shortCode', in the given example. The console is indicating I can't with dot notation, and I can't find any documentation on it.

{    
  "key2": "cj11b1ygp0000jcgubpe5mso3",
  "order": {
    "amount": 74.22,
    "dateCreated": "2017-04-02T19:15:33-04:00",
    "orderNumber": "cj11b1ygp0000jcgubpe5mso3",
    "shortCode": "SJLLDE"
  },
  "skey2": "SJLLDE"
}
like image 381
Pompey Magnus Avatar asked Aug 28 '26 21:08

Pompey Magnus


1 Answers

To scan by a nested attribute, you should use ExpressionAttributeNames parameter to pass each path component (i.e. order and shortCode) separately into FilterExpression like shown below:

var params = {
    TableName: 'YOUR_TABLE_NAME',
    FilterExpression: "#order.#shortCode = :shortCodeValue",
    ExpressionAttributeNames: {
        '#order': 'order',
        "#shortCode": "shortCode"
    },
    ExpressionAttributeValues: {
        ':shortCodeValue': 'SJLLDE'
    }
};

dynamodbDoc.scan(params, function(err, data) {
});

Here is a link to documentation explaining this:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html#Expressions.ExpressionAttributeNames.NestedAttributes

like image 172
xtx Avatar answered Sep 03 '26 21:09

xtx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!