Node.js - collection.query.fetch()

Retrieve a page of results for a query. This is an alternative to collection.query.stream()

import { collection } from '@nitric/sdk'
const profiles = collection('profiles').for('reading')
const profileQuery = profiles.query()
const results = await profileQuery.fetch()

Examples

Paging through results from a query

import { collection } from '@nitric/sdk'
const profiles = collection('profiles').for('reading')
const profileQuery = profiles.query()
let results = await profileQuery.fetch()
do {
for (const doc of results.documents()) {
// Do something with the document
console.log(doc)
}
if (pagingToken) {
profileQuery.pagingFrom(pagingToken)
results = await profileQuery.fetch()
}
} while (results.documents().length > 0 || results.pagingToken)

See also

Last updated on Dec 19, 2024