Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running queries in firebase using async / await

Appreciating that firebase has added support for promises, is there a way to run a query like the following inside of an async function?:

const eventref = this.db.ref('cats/whiskers');
const value = await eventref.once('value')

Running the above returns a promise for value, I'm hoping to get the json blob that is stored at cats/whiskers.

like image 440
fox Avatar asked May 01 '17 00:05

fox


1 Answers

The result of value is a snapshot, we need 1 more step to get the value. This should be like:

const eventref = this.db.ref('cats/whiskers');
const snapshot = await eventref.once('value');
const value = snapshot.val();
like image 135
Hank Phung Avatar answered Nov 18 '22 20:11

Hank Phung