Fetching all attributes in query of local secondary index with projection KEYS_ONLY
hammadzz opened this issue · 3 comments
hammadzz commented
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()
cdhowie commented
@hammadzz Simply omit the .attributes()
call and the entire object will be fetched. (Well, all attributes present in the index will be fetched.)
hammadzz commented
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?
cdhowie commented
@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 => { /* ... */ })