【问题标题】:How get the number of documents firebase? [duplicate]如何获取firebase文件的数量? [复制]
【发布时间】:2019-09-10 20:46:41
【问题描述】:

如何从 firebase 实时数据库中获取文档数量? 我只为 firebase firestore 找到答案。

【问题讨论】:

  • 它对firestore集合的回答,我需要实时数据库
  • 可以搜索标签的组合,所以:stackoverflow.com/…

标签: javascript firebase-realtime-database


【解决方案1】:

如果您想在 Firebase 实时数据库中获取您孩子的数量,您必须在 DataSnapshot 对象上使用 getChildrenCount()。我建议阅读Firebase Docs 以获取更多信息。

Here 也是如何使用它的示例。

以下代码示例也来自Firebase Docs。稍微修改了一下。

final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference();

// Attach a listener to print out the number of total children
ref.addValueEventListener(new ValueEventListener() {
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
    long count = dataSnapshot.getChildrenCount();
    System.out.println(count);
  }

  @Override
  public void onCancelled(DatabaseError databaseError) {
    System.out.println("The read failed: " + databaseError.getCode());
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 2018-07-23
    • 2018-10-03
    • 2020-07-29
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多