Firebase 总用户数 [英] Firebase total user count

查看:51
本文介绍了Firebase 总用户数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 firebase 中获取所有用户的数量?(通过密码、facebook、twitter 等进行身份验证)所有社交和电子邮件和密码身份验证用户的总数.

Is there a way to get all the users' count in firebase? (authenticated via password, facebook, twitter, etc.) Total of all social and email&password authenticated users.

推荐答案

没有内置的方法来获取总用户数.

There's no built-in method to do get the total user count.

您可以保留 userId 的索引并将它们拉下来并计算它们.但是,这需要下载所有数据才能进行计数.

You can keep an index of userIds and pull them down and count them. However, that would require downloading all of the data to get a count.

{
  "userIds": {
    "user_one": true,
    "user_two": true,
    "user_three": true 
  }
}

然后在下载数据时可以调用snapshot.numChildren():

Then when downloading the data you can call snapshot.numChildren():

var ref = new Firebase('<my-firebase-app>/userIds');
ref.once('value', function(snap) {
  console.log(snap.numChildren());
});

如果您不想下载数据,可以使用 交易.

var ref = new Firebase('<my-firebase-app>');
ref.createUser({ email: '', password: '', function() {
  var userCountRef = ref.child('userCount');
  userCountRef.transaction(function (current_value) {
    // increment the user count by one
    return (current_value || 0) + 1;
  });
});

然后你可以实时监听用户:

Then you can listen for users in realtime:

var ref = new Firebase('<my-firebase-app>/userCount');
ref.on('value', function(snap) {
  console.log(snap.val());
});

这篇关于Firebase 总用户数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆