Check if value exists in firebase DB

后端 未结 4 2024
萌比男神i
萌比男神i 2020-11-29 20:24

Is there a method in firebase, which can check if value exist in DB? Firebase has method .exists(), but according to docs it checks only the keys.

I have the followi

4条回答
  •  难免孤独
    2020-11-29 20:58

    This is how I searched for a url value in Firebasebase database on my project:

    
    const searchFirebase = (url, idx) => 
    {
         firebase
           .app()
           .database()
           .ref("recipes")
           .orderByChild("url")
           .equalTo(url)
           .once("value", (snapshot) => {
             if (snapshot.exists()) {
               const userData = snapshot.val();
               console.log("exists!", userData);
               document.querySelector(`[data-recipe-id="${idx}"]`)
               .classList.replace('fav-heart', 'unfav-heart'); 
             } else {
               return false; 
             }
           });
    }
    
    

提交回复
热议问题