Skip to content

Add a snippet demonstrating a subcollection query. #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions firestore-next/test.firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,18 @@ describe("firestore", () => {
// [END get_multiple_all]
});

it("should get all documents from a subcollection", async () => {
// [START firestore_query_subcollection]
const { collection, getDocs } = require("firebase/firestore");
// Query a reference to a subcollection
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
// [END firestore_query_subcollection]
});

it("should listen on multiple documents #UNVERIFIED", (done) => {
// [START listen_multiple]
const { collection, query, where, onSnapshot } = require("firebase/firestore");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START firestore_query_subcollection_modular]
import { collection, getDocs } from "firebase/firestore";
// Query a reference to a subcollection
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
// [END firestore_query_subcollection_modular]