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
and Serials
.
But how can I get collections from Films
for example?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With