Last active
September 22, 2020 17:38
-
-
Save PierBover/2c0f32d45f71a0b76e935298db7d9307 to your computer and use it in GitHub Desktop.
FaunaDB client aggregation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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