【问题标题】:Is it possible to find the number of fields in Firebase Firestore document.How can i do it in Android Studio是否可以在 Firebase Firestore 文档中找到字段数。我如何在 Android Studio 中做到这一点
【发布时间】:2019-02-13 16:44:54
【问题描述】:

我想查找 Firebase 文档中的字段总数。我该怎么做?

【问题讨论】:

    标签: java android firebase google-cloud-firestore


    【解决方案1】:

    要获取特定文档中的字段数,请使用以下代码行:

    FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
    DocumentReference docRef = rootRef.collection("yourCollection").document("yourDocument");
    docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if (task.isSuccessful()) {
                DocumentSnapshot document = task.getResult();
                if (document.exists()) {
                    Map<String, Object> map = document.getData();
                    Log.d(TAG, String.valueOf(map.size()));
                }
            }
        }
    });
    

    【讨论】:

    • 优秀。我的搜索到此结束。
    猜你喜欢
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 2011-03-08
    • 2019-07-25
    • 1970-01-01
    相关资源
    最近更新 更多