Skip to content

Commit 1852962

Browse files
authored
Add a snippet demonstrating a subcollection query. (#339)
1 parent e2beb93 commit 1852962

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

firestore-next/test.firestore.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,18 @@ describe("firestore", () => {
683683
// [END get_multiple_all]
684684
});
685685

686+
it("should get all documents from a subcollection", async () => {
687+
// [START firestore_query_subcollection]
688+
const { collection, getDocs } = require("firebase/firestore");
689+
// Query a reference to a subcollection
690+
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
691+
querySnapshot.forEach((doc) => {
692+
// doc.data() is never undefined for query doc snapshots
693+
console.log(doc.id, " => ", doc.data());
694+
});
695+
// [END firestore_query_subcollection]
696+
});
697+
686698
it("should listen on multiple documents #UNVERIFIED", (done) => {
687699
// [START listen_multiple]
688700
const { collection, query, where, onSnapshot } = require("firebase/firestore");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./firestore-next/test.firestore.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START firestore_query_subcollection_modular]
8+
import { collection, getDocs } from "firebase/firestore";
9+
// Query a reference to a subcollection
10+
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
11+
querySnapshot.forEach((doc) => {
12+
// doc.data() is never undefined for query doc snapshots
13+
console.log(doc.id, " => ", doc.data());
14+
});
15+
// [END firestore_query_subcollection_modular]

0 commit comments

Comments
 (0)