Skip to content

Commit 6d1e83d

Browse files
authored
Add snippet for getCollections() (#9)
1 parent ad5298a commit 6d1e83d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

firestore/main/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ function getAll(db) {
560560
return allCities;
561561
}
562562

563+
function getCollections(db) {
564+
// [START get_collections]
565+
var sfRef = db.collection('cities').doc('SF');
566+
sfRef.getCollections().then(collections => {
567+
collections.forEach(colleciton => {
568+
console.log('Found subcollection with id:', collection.id);
569+
});
570+
});
571+
// [END get_collections]
572+
}
573+
563574
// ============================================================================
564575
// https://firebase.google.com/docs/firestore/server/query-data
565576
// ============================================================================
@@ -922,6 +933,10 @@ describe("Firestore Smoketests", () => {
922933
return getAll(db)
923934
});
924935

936+
it("should get all subcollections of a document", () => {
937+
return getCollections(db);
938+
});
939+
925940
it("should query and filter", () => {
926941
return queryAndFilter(db)
927942
});

0 commit comments

Comments
 (0)