awslabs / dynamodb-data-mapper-js

A schema-based data mapper for Amazon DynamoDB.
https://awslabs.github.io/dynamodb-data-mapper-js/
Apache License 2.0
817 stars 106 forks source link

Make a Query over an Index #133

Closed skrosoft closed 5 years ago

skrosoft commented 5 years ago

Hello,

Is there a working example of a query over an Index?

I am trying this using QueryOptions since 2 days ago and can't get it working...

The documentation says:

You cannot define a filter expression based on a partition key or a sort key.

So, how can I make a "where" over my indexed column?

Thanks

skrosoft commented 5 years ago

Ok, I could resolve my problem, here is the code:

    const params = {
        subject: 'authorizationToken',
        type: 'Equals',
        object: '9c75a9e5-8d8b-41b6-99c7-30020573ced2'
    };

    const options = {
        indexName: 'authorizationTokenIndex'
    };

    for await (const foo of mapper.query(PaymentServiceProvider, params, options)) {
        console.log("FOUND: ", foo);
    }

Hope it will help someone.