E
E
Eugene2019-02-23 23:33:25
Node.js
Eugene, 2019-02-23 23:33:25

How to formulate a query in firebase?

Hello, I'm asking for help in formulating a request to the Firebase Realtime DB from Node.js. There is a code

var array = [];
snapshot.forEach(function(childSnapshot) {//Получаем путь к нужным таблицам childSnapshot.val().id
     firebase.database().ref("/posts/" + childSnapshot.val().id).once('value', (snapshot) => {
          array.push(snapshot.key);
     });
});
console.log(array);//В этом месте проблема

In the place where the problem is indicated, the array array is empty, because requests are not asynchronous, and also due to forEach there are too many calls to the database, is there an option to make calls to several elements in the database at once using 1 request, and how to overcome the problem with asynchrony. I will be grateful for your answers.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question