Answers for "how to set two query in firebase option quer"

11

how to query in firestore

db.collection("cities").where("capital", "==", true)
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            // doc.data() is never undefined for query doc snapshots
            console.log(doc.id, " => ", doc.data());
        });
    })
    .catch(function(error) {
        console.log("Error getting documents: ", error);
    });
Posted by: Guest on May-28-2020
0

multiple query at once in firebase

function doSomething(...){
    let result1 = [];
    let result2 = [];
    admin.firestore().collection('...').where('some condition').get()
    .then((results: any)=>{
        results.forEach((element: any)=>{
            if(some other condition){
                result1.push(element);
            }
    })
    .catch((error: any)=>{//log the error});
    admin.firestore().collection('...').where('yet another condition').orderBy(...).get()
    .then((results: any)=>{
        results.forEach((element: any)=>{
            result2.push(func(element))  //func is some manipulation
    })
    .catch((error: any)=>{//log the error});
    return makeCalculation(result1, result2);
}
Posted by: Guest on August-27-2020
0

firebase query multiple keys

var keys = [ 
  "-Ke1uhoT3gpHR_VsehIv",
  "-Ke8qAECkZC9ygGW3dEJ",
  "-Ke8qMU7OEfUnuXSlhhl"
];
var promises = keys.map(function(key) {
  return firebase.database().ref("/items/").child(key).once("value");
});
Promise.all(promises).then(function(snapshots) {
  snapshots.forEach(function(snapshot) {
    console.log(snapshot.key+": "+snapshot.val());
  });
});
Posted by: Guest on July-08-2020

Browse Popular Code Answers by Language