Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**********************************************
- // Get all documents
- //**********************************************
- router.get('/', async function(req, res, next) {
- const title = 'Boozeyum';
- let cityRef = await db.collection('cities');
- const data = [];
- let getDoc = await cityRef.get()
- .then(snapshot => {
- snapshot.docs.forEach(doc => {
- data.push(doc.data());
- });
- return snapshot.docs.map(doc => doc.data());
- })
- .catch(err => {
- console.log('Error getting document', err);
- return null;
- });
- return res.render('index', { title: title, data: data });
- });
- //**********************************************
- // Get document item
- //**********************************************
- router.get('/', async function(req, res, next) {
- const title = 'Boozeyum';
- let cityRef = await db.collection('cities').doc('SF');
- let getDoc = await cityRef.get().then(doc => {
- if (!doc.exists) return null;
- console.log('Document data:', doc.data());
- return doc.data();
- })
- .catch(err => {
- console.log('Error getting document', err);
- return null;
- });
- console.log(getDoc);
- return res.render('index', { title: title, data: getDoc });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement