Firebase 将用户编号检索到网络



您好,我正在为我的应用程序构建一个小仪表板。我对Firebase有点陌生,但它为我节省了很多时间。因此,我想做的是将来从数据库stright检索到Web仪表板或任何其他相关数据的总注册用户数。所以我没有做的是一个小的登录表单,我可以登录。也许有人有任何类似的经历,我在图片中添加了数据库的结构。

    // Initialize Firebase
var config = {
  apiKey: "...",
      authDomain: "...",
      databaseURL: "...",
      storageBucket: "...",
  messagingSenderId: "..."
};
firebase.initializeApp(config);
// Firebase Variables
var auth = firebase.auth();
// on state changed
auth.onAuthStateChanged(firebaseUser => {
  // check email
  if(firebaseUser){
    currentEmail.innerHTML = auth.currentUser.email
    currentEmail.style.display = 'block';
    singoutButton.style.display = 'block';
    //singupForm.style.display = 'none';
    signin.style.display = 'none';
    signinEmail.style.display = 'none';
    signinPassword.style.display = 'none';
    signintext.style.display = 'none';
    welcometext.style.display = 'block';
    window.location = 'index.html';
  } else{
    signintext.style.display = 'block';
    welcometext.style.display = 'none';
    signin.style.display = 'block';
    signinEmail.style.display = 'block';
    signinPassword.style.display = 'block';
    singoutButton.style.display = 'none';
    //singupForm.style.display = 'block';
    currentEmail.style.display = 'none';
  }
});

火力基地

要检索用户数,请尝试以下操作:

var ref = firebase.database().ref("users");
ref.once("value").then(function(snapshot) {
var numberOfChildren = snapshot.numChildren();
});

假设users是根节点的直接子节点。

numChildren()返回编号

返回此数据快照的子属性的数目。

更多信息在这里:

https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#numChildren

最新更新