如何检查实时数据库FIREBASE中的数据

时间:2019-05-28 21:04:41

标签: javascript firebase firebase-realtime-database

我想检查/比较数据中是否包含值:

1

示例:

const uid = '35nv594aotgcv'

#check if uid is inside

firebase
 .database()
   .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
     .once("value", snapshot => {
         if (snapshot.exists()) {
            const data = snapshot.val(); // data are the other two uid's in the image above
         }
     });

那么如何检查const uid = '35nv594aotgcv'是否在快照数据中?

或者如果我有一个带有const uids = ['234', '343', '3242', ...]的uid的数组

1 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,那么您正在寻找DataSnapshot.hasChild()。这样,您可以检查快照是否具有特定的子节点。

类似的东西:

firebase
 .database()
 .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
 .once("value", snapshot => {
   if (snapshot.hasChild('35nv594aotgcv')) {
     console.log('Yes');
   }
 });