clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetching all attributes in query of local secondary index with projection KEYS_ONLY

hammadzz opened this issue · comments

For a query like below is there a way to specify get all attributes (fetch) rather than have to explicitly specify each one?

Account.query('foo').usingIndex('YearIndex')
.where('year').equals('2018')
.attributes(['id', 'year', 'a', 'b', 'c'])
.execAsync()

@hammadzz Simply omit the .attributes() call and the entire object will be fetched. (Well, all attributes present in the index will be fetched.)

As the attributes in the index are KEYS_ONLY that would be none of the attributes. I assume there is no feature to fetch all attributes, is that correct?

@hammadzz That is correct; the index doesn't have the attributes. You'll have to get them from the table.

Using a promise library like bluebird, this should work to concurrently fetch all of the "real" objects out of the table based on the results of the query:

const Promise = require('bluebird');

Promise.resolve(
  Account.query('...').usingIndex('...')
  .where('...').equals('...')
  .execAsync()
)
.get('Items')
.map(i => Account.getAsync(i.get()))
.then(items => { /* ... */ })