Reputation: 73
I am trying to write a cloud function which will be triggered by http and I will send a date as input and based on that date I want to fetch the list of games in my firebase db.
I am not sure how to fetch the data from the snapshot i am receiving from promise.
Code:
enter code hereexport const checkGameResult =
functions.https.onRequest((request, response) => {
const date:string = request.query.gameDate;
console.log(date);
admin.database().ref('activegames/'+date).once('value').then(result=>{
console.log('result: ');
console.log(result);
console.log('result[0]: '+result[0]);
response.send(date);
}).catch(error=>{
response.status(500).status(error);
});
});
I am not sure how to fetch the data from the snapshot i am receiving from promise. Please advise.
Upvotes: 2
Views: 2751
Reputation: 317487
Call val()
on the snapshot to get a raw JavaScript object with the contents of the location of the reference. Use that to send back the data you want.
admin.database().ref('activegames/'+date).once('value').then(result=>{
console.log('result: ');
console.log(result.val());
Upvotes: 3