Skip to content

Instantly share code, notes, and snippets.

@abegehr
Created May 6, 2020 10:30
Show Gist options
  • Save abegehr/ff11cc0d5163e416a845126e1077c33e to your computer and use it in GitHub Desktop.
Save abegehr/ff11cc0d5163e416a845126e1077c33e to your computer and use it in GitHub Desktop.
Fetching data from Firestore sequentially.
// https://firebase.google.com/docs/firestore/quickstart
var db = firebase.firestore();
async function fetchArticle(articleId, authorId) {
try {
// get author and article docs sequentially
const authorSnap = await db.doc("authors/" + authorId).get();
const articleSnap = await db.doc("articles/" + articleId).get();
}
catch (err) {/* handle error */}
// extract data
const authorData = authorSnap.data();
const articleData = articleSnap.data();
// save to state
this.setState({authorData, articleData});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment