Skip to content

Commit e26834e

Browse files
committed
Solution aggregation
1 parent ee83fe4 commit e26834e

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

firestore/test.solution-aggregation.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// [START sample_doc]
2-
var arinellDoc = {
2+
const arinellDoc = {
33
name: 'Arinell Pizza',
44
avgRating: 4.65,
55
numRatings: 683
66
}
77
// [END sample_doc]
88

99
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");
1914

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);
2324
});
2425

2526
describe("solution-arrays", () => {
26-
it("should get a collection of ratings", () => {
27+
it("should get a collection of ratings", async () => {
2728
// [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);
3233
// [END get_collection_ratings]
3334
})
3435
});

0 commit comments

Comments
 (0)