From 15bd33fdb5d4291005db6faf9b140d998659a20e Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 29 Sep 2022 11:03:42 -0700 Subject: [PATCH 1/5] add simpler snippet --- firestore-next/test.firestore.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2469b736..120acb90 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1159,6 +1159,7 @@ describe("firestore", () => { }); describe("aggregate queries", () => { +<<<<<<< HEAD it("should fetch the count of documents in a collection", async () => { const { collection, getCountFromServer } = require("firebase/firestore"); // [START count_aggregate_collection] @@ -1177,6 +1178,24 @@ describe("firestore", () => { console.log('count: ', snapshot.data().count); // [END count_aggregate_query] }); +======= + it("should fetch the count of documents in a collection", async () => { + // [START count_aggregate_collection] + const coll = collection(db, "cities"); + const snapshot = await getCountFromServer(coll); + console.log('count: ', snapshot.data().count); + // [END count_aggregate_collection] + }); + + it("should fetch the count of documents in a query", async () => { + // [START count_aggregate_query] + const coll = collection(db, "cities"); + const query = query(coll, where("state", "==", "CA")); + const snapshot = await getCountFromServer(query); + console.log('count: ', snapshot.data().count); + // [END count_aggregate_query] + }); +>>>>>>> 09d36f3 (add simpler snippet) }); // TODO: Break out into separate file From e0977649fef94a94ce5abb4b0cb67ccaad696f71 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 20 Oct 2022 15:03:37 -0700 Subject: [PATCH 2/5] consts --- firestore-next/test.firestore.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 120acb90..2469b736 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1159,7 +1159,6 @@ describe("firestore", () => { }); describe("aggregate queries", () => { -<<<<<<< HEAD it("should fetch the count of documents in a collection", async () => { const { collection, getCountFromServer } = require("firebase/firestore"); // [START count_aggregate_collection] @@ -1178,24 +1177,6 @@ describe("firestore", () => { console.log('count: ', snapshot.data().count); // [END count_aggregate_query] }); -======= - it("should fetch the count of documents in a collection", async () => { - // [START count_aggregate_collection] - const coll = collection(db, "cities"); - const snapshot = await getCountFromServer(coll); - console.log('count: ', snapshot.data().count); - // [END count_aggregate_collection] - }); - - it("should fetch the count of documents in a query", async () => { - // [START count_aggregate_query] - const coll = collection(db, "cities"); - const query = query(coll, where("state", "==", "CA")); - const snapshot = await getCountFromServer(query); - console.log('count: ', snapshot.data().count); - // [END count_aggregate_query] - }); ->>>>>>> 09d36f3 (add simpler snippet) }); // TODO: Break out into separate file From 794bca0e9175c167c66f9923ee65729b8d66a484 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 16 Feb 2023 11:39:01 -0800 Subject: [PATCH 3/5] add OR snippets --- firestore-next/test.firestore.js | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2469b736..30efd886 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1090,6 +1090,77 @@ describe("firestore", () => { limit(25)); // [END paginate] }); + + it("should handle OR queries", async () => { + const { collection, query, where, and } = require("firebase/firestore"); + // [START or_query] + const query = query(collection(db, "cities"), and( + where('name', '>', 'L'), + or( + where('capital', '==', true), + where('population', '>=', 1000000) + ) + )); + // [END or_query] + }); + + it("should allow for 30 or fewer disjunctions", async () => { + const { collection, query, where, and } = require("firebase/firestore"); + const collectionRef = collection(db, "cities"); + // [START one_disjunction] + query(collectionRef, where("a", "==", 1)); + // [END one_disjunction] + + // [START two_disjunctions] + query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) )); + // [END two_disjunctions] + + // [START four_disjunctions] + query(collectionRef, + or( and( where("a", "==", 1), where("c", "==", 3) ), + and( where("a", "==", 1), where("d", "==", 4) ), + and( where("b", "==", 2), where("c", "==", 3) ), + and( where("b", "==", 2), where("d", "==", 4) ) + ) + ); + // [END four_disjunctions] + + // [START four_disjunctions_compact] + query(collectionRef, + and( or( where("a", "==", 1), where("b", "==", 2) ), + or( where("c", "==", 3), where("d", "==", 4) ) + ) + ); + // [END four_disjunctions_compact] + + expect(() => { + // [START 50_disjunctions] + query(collectionRef, + and( where("a", "in", [1, 2, 3, 4, 5]), + where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + ) + ); + // [END 50_disjunctions] + }).to.throw; + + // [START 20_disjunctions] + query(collectionRef, + or( where("a", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), + where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + ) + ); + // [END 20_disjunctions] + + // [START 10_disjunctions] + query(collectionRef, + and( where("a", "in", [1, 2, 3, 4, 5]), + or( where("b", "==", 2), + where("c", "==", 3) + ) + ) + ); + // [END 10_disjunctions] + }); }); describe('collectionGroup(landmarks)', () => { From 602c44e8a3af46d58d08370dcef25bf598554468 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 16 Feb 2023 11:40:40 -0800 Subject: [PATCH 4/5] run snippets --- .../test-firestore/four_disjunctions.js | 15 +++++++++++++++ .../test-firestore/four_disjunctions_compact.js | 13 +++++++++++++ .../test-firestore/one_disjunction.js | 9 +++++++++ .../firestore-next/test-firestore/or_query.js | 15 +++++++++++++++ .../test-firestore/two_disjunctions.js | 9 +++++++++ 5 files changed, 61 insertions(+) create mode 100644 snippets/firestore-next/test-firestore/four_disjunctions.js create mode 100644 snippets/firestore-next/test-firestore/four_disjunctions_compact.js create mode 100644 snippets/firestore-next/test-firestore/one_disjunction.js create mode 100644 snippets/firestore-next/test-firestore/or_query.js create mode 100644 snippets/firestore-next/test-firestore/two_disjunctions.js diff --git a/snippets/firestore-next/test-firestore/four_disjunctions.js b/snippets/firestore-next/test-firestore/four_disjunctions.js new file mode 100644 index 00000000..12ed21ee --- /dev/null +++ b/snippets/firestore-next/test-firestore/four_disjunctions.js @@ -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 four_disjunctions_modular] +query(collectionRef, + or( and( where("a", "==", 1), where("c", "==", 3) ), + and( where("a", "==", 1), where("d", "==", 4) ), + and( where("b", "==", 2), where("c", "==", 3) ), + and( where("b", "==", 2), where("d", "==", 4) ) + ) +); +// [END four_disjunctions_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/four_disjunctions_compact.js b/snippets/firestore-next/test-firestore/four_disjunctions_compact.js new file mode 100644 index 00000000..7421b01a --- /dev/null +++ b/snippets/firestore-next/test-firestore/four_disjunctions_compact.js @@ -0,0 +1,13 @@ +// 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 four_disjunctions_compact_modular] +query(collectionRef, + and( or( where("a", "==", 1), where("b", "==", 2) ), + or( where("c", "==", 3), where("d", "==", 4) ) + ) +); +// [END four_disjunctions_compact_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/one_disjunction.js b/snippets/firestore-next/test-firestore/one_disjunction.js new file mode 100644 index 00000000..f2a5ebbe --- /dev/null +++ b/snippets/firestore-next/test-firestore/one_disjunction.js @@ -0,0 +1,9 @@ +// 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 one_disjunction_modular] +query(collectionRef, where("a", "==", 1)); +// [END one_disjunction_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/or_query.js b/snippets/firestore-next/test-firestore/or_query.js new file mode 100644 index 00000000..f9655e59 --- /dev/null +++ b/snippets/firestore-next/test-firestore/or_query.js @@ -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 or_query_modular] +const query = query(collection(db, "cities"), and( + where('name', '>', 'L'), + or( + where('capital', '==', true), + where('population', '>=', 1000000) + ) +)); +// [END or_query_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/two_disjunctions.js b/snippets/firestore-next/test-firestore/two_disjunctions.js new file mode 100644 index 00000000..e9015fc3 --- /dev/null +++ b/snippets/firestore-next/test-firestore/two_disjunctions.js @@ -0,0 +1,9 @@ +// 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 two_disjunctions_modular] +query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) )); +// [END two_disjunctions_modular] \ No newline at end of file From 7e4874cadf21d09e72a034d061abf390e8049f81 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Tue, 21 Mar 2023 16:45:17 -0400 Subject: [PATCH 5/5] fix web snippet --- firestore-next/test.firestore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 30efd886..edb1b61b 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1094,8 +1094,8 @@ describe("firestore", () => { it("should handle OR queries", async () => { const { collection, query, where, and } = require("firebase/firestore"); // [START or_query] - const query = query(collection(db, "cities"), and( - where('name', '>', 'L'), + const q = query(collection(db, "cities"), and( + where('state', '==', 'CA'), or( where('capital', '==', true), where('population', '>=', 1000000)