Firebase wait for response

Viewed 4318

If i have something like this

const query = firebase.database().ref("/posts").orderByChild('postid').equalTo(1);
query.once('value', snapshot=>{
  if(snapshot.val() == "XYZ"){
    console.log("true");
    return true;
  }
});
console.log("false");
return false

why is is this printing
false
true

how can i force to wait for the answer of query before jumping to the return false?

3 Answers
Related