|
1 | 1 | // [START sample_doc]
|
2 |
| -var arinellDoc = { |
| 2 | +const arinellDoc = { |
3 | 3 | name: 'Arinell Pizza',
|
4 | 4 | avgRating: 4.65,
|
5 | 5 | numRatings: 683
|
6 | 6 | }
|
7 | 7 | // [END sample_doc]
|
8 | 8 |
|
9 | 9 | describe("firestore-solution-arrays", () => {
|
10 |
| - var db; |
11 |
| - before(() => { |
12 |
| - var config = { |
13 |
| - apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", |
14 |
| - authDomain: "firestorequickstarts.firebaseapp.com", |
15 |
| - projectId: "firestorequickstarts", |
16 |
| - }; |
17 |
| - var app = firebase.initializeApp(config, "solution-arrays"); |
18 |
| - db = firebase.firestore(app); |
| 10 | + let db; |
| 11 | + before(async () => { |
| 12 | + const { initializeApp } = require("@firebase/app"); |
| 13 | + const { getFirestore, collection, doc, setDoc } = require("@firebase/firestore"); |
19 | 14 |
|
20 |
| - return db.collection("restaurants") |
21 |
| - .doc("arinell-pizza") |
22 |
| - .set(arinellDoc); |
| 15 | + const config = { |
| 16 | + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", |
| 17 | + authDomain: "firestorequickstarts.firebaseapp.com", |
| 18 | + projectId: "firestorequickstarts", |
| 19 | + }; |
| 20 | + const app = initializeApp(config, "solution-arrays"); |
| 21 | + db = getFirestore(app); |
| 22 | + |
| 23 | + await setDoc(doc(collection(db, "restaurants"), "arinell-pizza"), arinellDoc); |
23 | 24 | });
|
24 | 25 |
|
25 | 26 | describe("solution-arrays", () => {
|
26 |
| - it("should get a collection of ratings", () => { |
| 27 | + it("should get a collection of ratings", async () => { |
27 | 28 | // [START get_collection_ratings]
|
28 |
| - db.collection("restaurants") |
29 |
| - .doc("arinell-pizza") |
30 |
| - .collection("ratings") |
31 |
| - .get() |
| 29 | + const { collection, doc, getDocs } = require("@firebase/firestore"); |
| 30 | + |
| 31 | + const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); |
| 32 | + const ratingsDocs = await getDocs(ratingsRef); |
32 | 33 | // [END get_collection_ratings]
|
33 | 34 | })
|
34 | 35 | });
|
|
0 commit comments