Skip to content

sample: get docs from a Firestore subcollection #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,27 @@ public void onComplete(@NonNull Task<QuerySnapshot> task) {
// [END get_multiple_all]
}

public void getAllDocsSubcollection() {
// [START firestore_query_subcollection]
db.collection("cities")
.document("SF")
.collection("landmarks")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
// [END firestore_query_subcollection]
}

public void listenToMultiple() {
// [START listen_multiple]
db.collection("cities")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,23 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
// [END get_multiple_all]
}

private fun getAllDocsSubcollection() {
// [START firestore_query_subcollection]
db.collection("cities")
.document("SF")
.collection("landmarks")
.get()
.addOnSuccessListener { result ->
for (document in result) {
Log.d(TAG, "${document.id} => ${document.data}")
}
}
.addOnFailureListener { exception ->
Log.d(TAG, "Error getting documents: ", exception)
}
// [END firestore_query_subcollection]
}

private fun listenToMultiple() {
// [START listen_multiple]
db.collection("cities")
Expand Down