I connect the database from React Native project.
In my Firestore database Buildings/Taipei
, i want to get all of the collection ids like 201
202
203
I try to use the code:
const db = firebaseApp.firestore();
db.collection('Buildings').doc('Taipei')
.get()
.then(doc => {
console.log('get doc is =>');
console.log(doc);
}).catch(error => {
console.log(`error is ${error}`);
});
I can't see any collection id in the doc
.
Any help would be appreciated. Thanks in advance.
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.
CollectionReference collectionReference = FirebaseFirestore. getInstance(). collection("public_messages"); ArrayList<String> ids = new ArrayList<>(); //Contains your keys ArrayList<Task<QuerySnapshot>> tasks = new ArrayList<>(); for (String id : ids) { Task<QuerySnapshot> task = collectionReference.
Unfortunately what you want to do is not currently possible in the mobile/web client.
The getCollections() method of the Cloud Firestore server client libraries lists all subcollections of a document reference.
Retrieving a list of collections is not possible with the mobile/web client libraries. You should only look up collection names as part of administrative tasks in trusted server environments. If you find that you need this capability in the mobile/web client libraries, consider restructuring your data so that subcollection names are predictable.
Source: List Subcollections of Document
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