'Get all Collections that are declared on document Swift Firestore Firebase
I have a document (lets call it d1) that has multiple collections.
d1(FirestoreDocument) -> Collection1, Collection2, Collection3
These collections each have a unique name (in my case a date string with the format dd.MM.yy).
I need to retrieve all the documents that are that one collection. The problem is that I don't know how I can access a collection that I don't know the exact name of. Is there a function for firebase Firestore where you can for example call document.getAllCollections(completion...) and then get the documents for each collection individually?
Solution 1:[1]
There is a function for listing all collections called .listCollections() however it is a server-side function.
Meaning it's not available for client/mobile libraries
Since Swift is a mobile language it is not available there to my knowledge.
However, since you're formatting the subcollections as dd.MM.yy that means the subcollections are predictable (to a degree), so you could store a list of the subcollections a document has within it and then iterate over that list as a workaround, or iterate over a breadth of dates.
Another workaround would be to call listCollections server-side (assuming you have a server for your application written in Java, Python, Node.js, Go, PHP, C# or Ruby), and send that list of collections as a JSON array back to your client so it can iterate over it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
