Skip to content

Instantly share code, notes, and snippets.

View sunrise1234321's full-sized avatar

sunrise1234321

View GitHub Profile
@sunrise1234321
sunrise1234321 / 1-standard.js
Last active December 4, 2021 13:43 — forked from vladfr/1-standard.js
Use async/await and for..of in Cloud Firestore
// In a Firestore standard example, we quickly create a 'xmas tree' of nested stuff
// We use Promises directly: get().then(callback) and use snapshot.forEach() to iterate
let campaignsRef = db.collection('campaigns');
let activeCampaigns = campaignsRef.where('active', '==', true).select().get()
.then(snapshot => {
snapshot.forEach(campaign => {
console.log(campaign.id);
let allTasks = campaignsRef.doc(campaign.id).collection('tasks').get().then(
snapshot => {
snapshot.forEach(task => {