Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find the number of fields in Firebase Firestore document.How can i do it in Android Studio

I want to find the total number of fields in a Firebase document. How can I do it?

like image 314
Hamza Ramzan Avatar asked Oct 29 '25 04:10

Hamza Ramzan


1 Answers

To get the number of fields within a particular document, please use the following lines of code:

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()));
            }
        }
    }
});
like image 98
Alex Mamo Avatar answered Oct 30 '25 17:10

Alex Mamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!