Skip to content

Commit a80bfcb

Browse files
committed
Who knows... some changes that were lying around
1 parent 54df8d8 commit a80bfcb

File tree

5 files changed

+102
-22
lines changed

5 files changed

+102
-22
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ config.json
4242
.vscode
4343

4444
dist
45-
.cache
45+
.cache
46+
47+
service-account.json

firebase-cloud-functions/context.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"eventId": "eb6H4zSgQABVKKifYOV24u0+Z0k=",
3+
"timestamp": "2018-03-20T11:27:57.893Z",
4+
"eventType": "google.firebase.database.ref.create",
5+
"resource": {
6+
"service": "firebaseio.com",
7+
"name":
8+
"projects/_/instances/how-to-firebase-tutorials/refs/authenticated/react-chat/Default Chat Room/-L829b5QxEoINb1ft39v"
9+
},
10+
"authType": "USER",
11+
"auth": {
12+
"uid": "DNhXq7T4igfchsZDIhxBWbRquF03",
13+
"token": {
14+
"name": "Chris Esplin",
15+
"email_verified": true,
16+
"email": "[email protected]",
17+
"exp": 1521548871,
18+
"user_id": "DNhXq7T4igfchsZDIhxBWbRquF03",
19+
"picture":
20+
"https://lh4.googleusercontent.com/-ly98tZeA6F0/AAAAAAAAAAI/AAAAAAAAADk/G-1n2ID9bOw/photo.jpg",
21+
"iat": 1521545271,
22+
"sub": "DNhXq7T4igfchsZDIhxBWbRquF03",
23+
"aud": "how-to-firebase-tutorials",
24+
"auth_time": 1521545271,
25+
"iss": "https://securetoken.google.com/how-to-firebase-tutorials",
26+
"firebase": {
27+
"identities": { "google.com": ["116279478330828791198"], "email": ["[email protected]"] },
28+
"sign_in_provider": "google.com"
29+
}
30+
}
31+
},
32+
"params": { "room": "Default Chat Room", "key": "-L829b5QxEoINb1ft39v" }
33+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"displayName": "Chris Esplin",
3+
"email": "[email protected]",
4+
"message": "Let's try this again",
5+
"photoURL":
6+
"https://lh4.googleusercontent.com/-ly98tZeA6F0/AAAAAAAAAAI/AAAAAAAAADk/G-1n2ID9bOw/photo.jpg",
7+
"uid": "DNhXq7T4igfchsZDIhxBWbRquF03"
8+
}

write-your-first-query/complete.html

+28-14
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,40 @@
1414
<script src="https://how-to-firebase-tutorials.firebaseapp.com/__/firebase/init.js"></script>
1515

1616
<script>
17-
async function getPeople() {
17+
async function getPeople(gender = 'male') {
1818
// Data Structure
1919
// Collection: public
20-
// Doc: write-your-first-query
20+
// Doc: cloud-firestore
2121
// Collection: star-wars-people
22-
23-
const collection = firebase
24-
.firestore()
25-
.collection('public')
26-
.doc('write-your-first-query')
22+
const db = firebase.firestore();
23+
const collection = db.collection('public')
24+
.doc('cloud-firestore')
2725
.collection('star-wars-people');
28-
const snapshot = await collection.get();
29-
30-
snapshot.docs.forEach(doc => {
31-
console.log(doc.id, doc.data());
32-
});
26+
27+
// See Firebase docs: https://firebase.google.com/docs/firestore/query-data/queries
28+
29+
// Write query for filtered by gender and ordered by descending height ascending mass
30+
const query = collection
31+
.where('gender', '==', gender)
32+
.orderBy('height', 'desc')
33+
.orderBy('mass', 'asc')
34+
35+
// Get collection snapshot
36+
const snapshot = await query.get();
37+
38+
// Map through snapshot's docs
39+
return snapshot.docs.map(doc => ({__id: doc.id, ...doc.data()}));
3340
}
3441

35-
getPeople();
36-
42+
async function runQueries() {
43+
const males = await getPeople('male');
44+
const females = await getPeople('female');
45+
46+
console.table(males);
47+
console.table(females);
48+
}
49+
50+
runQueries();
3751
</script>
3852

3953
<h1>Page intentionally left blank</h1>

write-your-first-query/index.html

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<html>
22

33
<head>
4-
<title>First Firestore Query</title>
4+
<title>Firestore: where and orderBy</title>
55
</head>
66

77
<body>
@@ -14,20 +14,43 @@
1414
<script src="https://how-to-firebase-tutorials.firebaseapp.com/__/firebase/init.js"></script>
1515

1616
<script>
17-
async function getPeople() {
17+
async function getPeople(gender = 'male') {
1818
// Data Structure
1919
// Collection: public
20-
// Doc: write-your-first-query
20+
// Doc: cloud-firestore
2121
// Collection: star-wars-people
22+
const db = firebase.firestore();
23+
const collection = db.collection('public')
24+
.doc('cloud-firestore')
25+
.collection('star-wars-people');
2226

23-
console.log('TODO: get people!');
27+
// See Firebase docs: https://firebase.google.com/docs/firestore/query-data/queries
28+
29+
// Write query for filtered by gender and ordered by descending height ascending mass
30+
const query = collection
31+
.where('gender', '==', gender)
32+
.orderBy('height', 'asc')
33+
.orderBy('mass', 'asc')
34+
35+
// Get collection snapshot
36+
const snapshot = await query.get();
37+
38+
// Map through snapshot's docs
39+
return snapshot.docs.map(doc => ({__id: doc.id, ...doc.data()}));
2440
}
2541

26-
getPeople();
27-
42+
async function runQueries() {
43+
const males = await getPeople('male');
44+
const females = await getPeople('female');
45+
46+
console.table(males);
47+
console.table(females);
48+
}
49+
50+
runQueries();
2851
</script>
2952

30-
<h1>Page intentionally left blank</h1>
53+
<h1>This page intentionally left blank</h1>
3154

3255
</body>
3356

0 commit comments

Comments
 (0)