Fetching all collections in Firestore
There are limited public APIs to get a list of top-level collections. Mobile clients (Android, iOS, web) have no API. Node.js admin clients have listCollections() on Firestore to get that list. Or, if you're looking for subcollections nested under a document, use DocumentReference.listCollections().
If you want to get a list on any platform, you should maintain that list yourself in a known collection inside a known document id.
You can do the following:
const admin = require("firebase-admin");
const db = admin.firestore();
db.listCollections()
.then(snapshot=>{
snapshot.forEach(snaps => {
console.log(snaps["_queryOptions"].collectionId); // LIST OF ALL COLLECTIONS
})
})
.catch(error => console.error(error));
This works with NodeJS.
Remember that you will need to download firebase-admin
and do the necessary configuration for Firebase server side.
You can make a separate collection(say listOfCollections
) which contains all the other collection names as documents or in an array of strings in one document as an alternative.
Then, whenever you are adding a new collection first add its name to the listOfCollections
.