Reputation: 31
I am able to console.log the output properly, but when I try to return the array, it fails (ie: no output)
//get all geo route
app.get('/api/geo', function(req, res){
res.send(getGeo());
});
async function getGeo() {
let query = firestore.collection('geo'); //.where('foo', '==', 'bar');
let response = await query.listDocuments().then(documentRefs => {
return firestore.getAll(...documentRefs);
}).then(documentSnapshots => {
let geomatches = [];
for (let documentSnapshot of documentSnapshots) {
if (documentSnapshot.exists) {
//console.log(`Found document with data: ${documentSnapshot.id}`);
geomatches[documentSnapshot.id] = documentSnapshot.data();
}//if
}//for
return geomatches;
});
return response;
}
Upvotes: 0
Views: 115
Reputation: 6762
getGeo()
is an async
function. You should use await
to call it. Also declare your route callback as async
:
//get all geo route
app.get('/api/geo', async function(req, res){
res.send(await getGeo());
});
Upvotes: 1
Reputation: 145
use await
//get all geo route
app.get('/api/geo', async function(req, res){
res.send( await getGeo());
});
Upvotes: 1