Get Firestore subcollections
19,202
You can try
defaultStore?.collection("Category").document("Film").collection("firstFilm").getDocuments();
Because Films, Books etc are documents not collections as you can see. For more info read here Firestore data model
Author by
Vlad78
Updated on June 07, 2022Comments
-
Vlad78 about 2 years
I have a problem with getting data from the Firestore with a following structure:
Here is how I get category collection:
var defaultStore: Firestore? var location: [DocumentSnapshot] = [] override func viewDidLoad() { super.viewDidLoad() defaultStore = Firestore.firestore() defaultStore?.collection("Category").getDocuments { (querySnapshot: QuerySnapshot?, error: Error?) in if let error = error { print(error.localizedDescription) } else { self.location = (querySnapshot?.documents)! DispatchQueue.main.async { self.tableView.reloadData() } } } }
It gives me:
Books
,Films
,From test
andSerials
. But how can I get collections fromFilms
for example? -
Alexander over 4 yearsalso, we can use fhttps://firebaseopensource.com/projects/firebase/firebase-android-sdk/docs/ktx/firestore.md/
-
EngineSense over 3 yearsThis is really hard when it's come to using random id, You cannot simply get the collection of it's subcollection in method like the above. You need to loop it get it. But at final hard to implement.