My structure of Firestore database:
|
|=>root_collection
|
|=>doc1
|
To have a list that contains all the name of your documents within the root_collection, please use the following code:
firestore.collection("root_collection").get().addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
List list = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult()) {
list.add(document.getId());
}
Log.d(TAG, list.toString());
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
The result in your logcat will be:
[doc1, doc2, doc3]
Remember, this code will work, only if you'll have some properties within those documents, otherwise you'll end ut with an empty list.