Martin Perussini
Martin Perussini

Reputation: 53

How to get all the docs from a subcollection in Firestore

I have a structure like this:

A (collection): {a (doc): {B (collection): {b (doc)}}}

I need to get the "b" from all the "a".

I don't need the relation between them, I only need all the "b".

I'm working in Android Studio with Java.

Upvotes: 0

Views: 35

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317928

To get all the documents in a subcollection, just build a path to it using the names of the collections and documents you know, and use get() to fetch the results, just like any other Query:

Query q = firestore.collection("A").document("a").collection("B");
q.get() // add listeners for the results

Upvotes: 1

Related Questions