Skip to content

Instantly share code, notes, and snippets.

@PierBover
Last active September 22, 2020 17:38
Show Gist options
  • Save PierBover/2c0f32d45f71a0b76e935298db7d9307 to your computer and use it in GitHub Desktop.
Save PierBover/2c0f32d45f71a0b76e935298db7d9307 to your computer and use it in GitHub Desktop.
FaunaDB client aggregation example
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: 'YOUR_FAUNA_SECRET'
});
async function countDocs () {
const refs = [];
let after, page;
try {
do {
page = await client.query(
q.Paginate(
q.Documents(q.Collection('MyCollection')),
{
after,
size: 100000
}
)
)
for (const ref of page.data) {
refs.push(ref)
}
after = page.after;
} while (after);
// count total refs
const totalRefs = refs.length;
console.log(totalRefs);
} catch (error) {
console.log(error);
}
}
countDocs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment