Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //**********************************************
  2. // Get all documents
  3. //**********************************************
  4. router.get('/', async function(req, res, next) {
  5. const title = 'Boozeyum';
  6. let cityRef = await db.collection('cities');
  7. const data = [];
  8. let getDoc = await cityRef.get()
  9. .then(snapshot => {
  10. snapshot.docs.forEach(doc => {
  11. data.push(doc.data());
  12. });
  13. return snapshot.docs.map(doc => doc.data());
  14. })
  15. .catch(err => {
  16. console.log('Error getting document', err);
  17. return null;
  18. });
  19.  
  20. return res.render('index', { title: title, data: data });
  21. });
  22.  
  23. //**********************************************
  24. // Get document item
  25. //**********************************************
  26. router.get('/', async function(req, res, next) {
  27. const title = 'Boozeyum';
  28. let cityRef = await db.collection('cities').doc('SF');
  29. let getDoc = await cityRef.get().then(doc => {
  30. if (!doc.exists) return null;
  31. console.log('Document data:', doc.data());
  32. return doc.data();
  33. })
  34. .catch(err => {
  35. console.log('Error getting document', err);
  36. return null;
  37. });
  38.  
  39. console.log(getDoc);
  40. return res.render('index', { title: title, data: getDoc });
  41. });
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement