Skip to content

Commit 7218a08

Browse files
authored
Firestore != queries (#156)
1 parent a845ea6 commit 7218a08

File tree

10 files changed

+708
-1062
lines changed

10 files changed

+708
-1062
lines changed

firestore/extend-with-functions/package-lock.json

Lines changed: 252 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore/extend-with-functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"compile": "cp ../../tsconfig.json.template ./tsconfig.json && tsc"
77
},
88
"dependencies": {
9-
"@google-cloud/firestore": "^4.1.1",
9+
"@google-cloud/firestore": "^4.4.0",
1010
"firebase-admin": "^9.2.0",
1111
"firebase-functions": "^3.11.0"
1212
}

firestore/main/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ async function queryAndFilter(db) {
577577
const nameQueryRes = await citiesRef.where('name', '>=', 'San Francisco').get();
578578
// [END example_filters]
579579

580-
for (const q of [stateQueryRes, populationQueryRes, nameQueryRes]) {
580+
// [START simple_query_not_equal]
581+
const capitalNotFalseRes = await citiesRef.where('capital', '!=', false).get();
582+
// [END simple_query_not_equal]
583+
584+
for (const q of [stateQueryRes, populationQueryRes, nameQueryRes, capitalNotFalseRes]) {
581585
q.forEach(d => {
582586
console.log('Get: ', d);
583587
});
@@ -610,12 +614,17 @@ async function inQueries(db) {
610614
const usaOrJapan = await citiesRef.where('country', 'in', ['USA', 'Japan']).get();
611615
// [END in_filter]
612616

617+
// [START not_in_filter]
618+
const notUsaOrJapan = await citiesRef.where('country', 'not-in', ['USA', 'Japan']).get();
619+
// [END not_in_filter]
620+
613621
// [START in_filter_with_array]
614622
const exactlyOneCoast = await citiesRef.where('region', 'in',
615623
[['west_coast', 'east_coast']]).get();
616624
// [END in_filter_with_array]
617625

618626
console.log('USA or Japan get: ', usaOrJapan);
627+
console.log('Not USA or Japan get: ', notUsaOrJapan);
619628
console.log('Exactly One Coast get: ', exactlyOneCoast);
620629
}
621630

firestore/main/package-lock.json

Lines changed: 400 additions & 575 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore/main/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"main": "index.js",
66
"scripts": {
77
"test-debug": "env DEBUG=firestore-snippets-node mocha index.js",
8-
"test": "env ./node_modules/.bin/mocha --timeout 20000 index.js",
8+
"test": "firebase --project=$GCLOUD_PROJECT emulators:exec './node_modules/.bin/mocha --timeout 20000 index.js'",
99
"compile": "cp ../../tsconfig.json.template ./tsconfig.json && tsc"
1010
},
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14-
"@google-cloud/firestore": "^2.6.0",
14+
"@google-cloud/firestore": "^4.4.0",
1515
"firebase-admin": "^9.2.0",
1616
"firebase-functions": "^3.11.0"
1717
},

firestore/solution-scheduled-backups/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ app.get('/cloud-firestore-export', async (req, res) => {
2020
};
2121

2222
const { outputUriPrefix } = req.query;
23-
if (!outputUriPrefix) {
23+
if (!(typeof outputUriPrefix === 'string')) {
2424
res.status(500).send('outputUriPrefix required');
25-
} else if (outputUriPrefix && outputUriPrefix.indexOf('gs://') !== 0) {
25+
return;
26+
} else if (outputUriPrefix.indexOf('gs://') !== 0) {
2627
res.status(500).send(`Malformed outputUriPrefix: ${outputUriPrefix}`);
28+
return;
2729
}
2830

2931
// Construct a backup path folder based on the timestamp
@@ -41,7 +43,7 @@ app.get('/cloud-firestore-export', async (req, res) => {
4143

4244
// If specified, mark specific collections for backup
4345
const { collections } = req.query;
44-
if (collections) {
46+
if (typeof collections === 'string') {
4547
body.collectionIds = collections.split(',');
4648
}
4749

0 commit comments

Comments
 (0)