我想查找 Firebase 文档中的字段总数。我该怎么做?
最佳答案
要获取特定文档中的字段数,请使用以下代码行:
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()));
}
}
}
});
关于java - 是否可以在 Firebase Firestore 文档中找到字段数。我如何在 Android Studio 中做到这一点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54675346/