繁体   English   中英

如何从firebase获取用户列表

[英]how to get a list of users from firebase

function getUsersEmail() {
  const dbRef = ref(getDatabase());
  get(child(dbRef, `users/`  )).then((snapshot) => {
    if (snapshot.exists()) {
      console.table(snapshot.val());
    } else {
      console.log("No data available");
    }
  }).catch((error) => {
    console.error(error);
  });
}

我能够将数据库 output 到控制台。 我想 output 只有用户的 email 地址。

JSON 文件

 {
"users": {
"2Le5WxOGnWWrkshsEqjeSIq527O2": {
  "email": "q5@gmail.com",
  "password": "qweqwe"
},
"2jn1YmI9twce3ylEP8wiu5QhUDf1": {
  "email": "55@gmail.com",
  "password": "qweqwe"
},

要检索所有用户和 output 仅他们的 email 地址:

get(child(dbRef, `users/`  )).then((snapshot) => {
  snapshot.forEach((child) => {
    console.log(child.val().email);
  })
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM