@@ -2,7 +2,7 @@ const debug = require('debug')('firestore-snippets-node');
2
2
3
3
// [START firestore_deps]
4
4
const { initializeApp, applicationDefault, cert } = require ( 'firebase-admin/app' ) ;
5
- const { getFirestore, Timestamp, FieldValue } = require ( 'firebase-admin/firestore' ) ;
5
+ const { getFirestore, Timestamp, FieldValue, Filter } = require ( 'firebase-admin/firestore' ) ;
6
6
// [END firestore_deps]
7
7
8
8
@@ -647,6 +647,41 @@ async function inQueries(db) {
647
647
console . log ( 'Exactly One Coast get: ' , exactlyOneCoast ) ;
648
648
}
649
649
650
+ /**
651
+ * Demonstrate OR queries
652
+ *
653
+ * @param {FirebaseFirestore.Firestore } db
654
+ */
655
+ async function orQueries ( db ) {
656
+ const citiesRef = db . collection ( 'cities' ) ;
657
+
658
+ // [START firestore_query_or]
659
+ const bigCities = await citiesRef
660
+ . where (
661
+ Filter . or (
662
+ Filter . where ( 'capital' , '==' , true ) ,
663
+ Filter . where ( 'population' , '>=' , 1000000 )
664
+ )
665
+ )
666
+ . get ( ) ;
667
+ // [END firestore_query_or]
668
+
669
+ // [START firestore_query_or_compound]
670
+ const bigCitiesInCalifornia = await citiesRef
671
+ . where ( 'state' , '==' , 'CA' )
672
+ . where (
673
+ Filter . or (
674
+ Filter . where ( 'capital' , '==' , true ) ,
675
+ Filter . where ( 'population' , '>=' , 1000000 )
676
+ )
677
+ )
678
+ . get ( ) ;
679
+ // [END firestore_query_or_compound]
680
+
681
+ console . log ( 'Big cities get: ' , bigCities ) ;
682
+ console . log ( 'Big cities in California get: ' , bigCitiesInCalifornia ) ;
683
+ }
684
+
650
685
async function orderAndLimit ( db ) {
651
686
const citiesRef = db . collection ( 'cities' ) ;
652
687
// [START firestore_query_order_limit]
@@ -1071,6 +1106,10 @@ describe('Firestore Smoketests', () => {
1071
1106
return inQueries ( db ) ;
1072
1107
} ) ;
1073
1108
1109
+ it ( 'should support or queries' , ( ) => {
1110
+ return orQueries ( db ) ;
1111
+ } ) ;
1112
+
1074
1113
it ( 'should order and limit' , ( ) => {
1075
1114
return orderAndLimit ( db ) ;
1076
1115
} ) ;
0 commit comments