@@ -1102,6 +1102,77 @@ describe("firestore", () => {
11021102 limit ( 25 ) ) ;
11031103 // [END paginate]
11041104 } ) ;
1105+
1106+ it ( "should handle OR queries" , async ( ) => {
1107+ const { collection, query, where, and } = require ( "firebase/firestore" ) ;
1108+ // [START or_query]
1109+ const query = query ( collection ( db , "cities" ) , and (
1110+ where ( 'name' , '>' , 'L' ) ,
1111+ or (
1112+ where ( 'capital' , '==' , true ) ,
1113+ where ( 'population' , '>=' , 1000000 )
1114+ )
1115+ ) ) ;
1116+ // [END or_query]
1117+ } ) ;
1118+
1119+ it ( "should allow for 30 or fewer disjunctions" , async ( ) => {
1120+ const { collection, query, where, and } = require ( "firebase/firestore" ) ;
1121+ const collectionRef = collection ( db , "cities" ) ;
1122+ // [START one_disjunction]
1123+ query ( collectionRef , where ( "a" , "==" , 1 ) ) ;
1124+ // [END one_disjunction]
1125+
1126+ // [START two_disjunctions]
1127+ query ( collectionRef , or ( where ( "a" , "==" , 1 ) , where ( "b" , "==" , 2 ) ) ) ;
1128+ // [END two_disjunctions]
1129+
1130+ // [START four_disjunctions]
1131+ query ( collectionRef ,
1132+ or ( and ( where ( "a" , "==" , 1 ) , where ( "c" , "==" , 3 ) ) ,
1133+ and ( where ( "a" , "==" , 1 ) , where ( "d" , "==" , 4 ) ) ,
1134+ and ( where ( "b" , "==" , 2 ) , where ( "c" , "==" , 3 ) ) ,
1135+ and ( where ( "b" , "==" , 2 ) , where ( "d" , "==" , 4 ) )
1136+ )
1137+ ) ;
1138+ // [END four_disjunctions]
1139+
1140+ // [START four_disjunctions_compact]
1141+ query ( collectionRef ,
1142+ and ( or ( where ( "a" , "==" , 1 ) , where ( "b" , "==" , 2 ) ) ,
1143+ or ( where ( "c" , "==" , 3 ) , where ( "d" , "==" , 4 ) )
1144+ )
1145+ ) ;
1146+ // [END four_disjunctions_compact]
1147+
1148+ expect ( ( ) => {
1149+ // [START 50_disjunctions]
1150+ query ( collectionRef ,
1151+ and ( where ( "a" , "in" , [ 1 , 2 , 3 , 4 , 5 ] ) ,
1152+ where ( "b" , "in" , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] )
1153+ )
1154+ ) ;
1155+ // [END 50_disjunctions]
1156+ } ) . to . throw ;
1157+
1158+ // [START 20_disjunctions]
1159+ query ( collectionRef ,
1160+ or ( where ( "a" , "in" , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ,
1161+ where ( "b" , "in" , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] )
1162+ )
1163+ ) ;
1164+ // [END 20_disjunctions]
1165+
1166+ // [START 10_disjunctions]
1167+ query ( collectionRef ,
1168+ and ( where ( "a" , "in" , [ 1 , 2 , 3 , 4 , 5 ] ) ,
1169+ or ( where ( "b" , "==" , 2 ) ,
1170+ where ( "c" , "==" , 3 )
1171+ )
1172+ )
1173+ ) ;
1174+ // [END 10_disjunctions]
1175+ } ) ;
11051176 } ) ;
11061177
11071178 describe ( 'collectionGroup(landmarks)' , ( ) => {
0 commit comments