Class Filter (7.5.0)

A Filter represents a restriction on one or more field values and can be used to refine the results of a Query . Filters s are created by invoking , , or and can then be passed to to create a new Query instance that also contains this Filter .

Package

@google-cloud/firestore

Methods

and(filters)

  static 
  
 and 
 (... 
 filters 
 : 
  
 Filter 
 []) 
 : 
  
 Filter 
 ; 
 

Creates and returns a new [Filter] Filter that is a conjunction of the given Filter s. A conjunction filter includes a document if it satisfies all of the given Filter s.

The returned Filter can be applied to [Query.where()], [Filter.or()], or [Filter.and()]. When applied to a [Query] Query it requires that documents must satisfy one of the provided Filter s.

Parameter
Name
Description
filters
Filter []

Optional. The Filter s for AND operation. These must be created with calls to , , or .

Returns
Type
Description

{Filter} The created Filter .

Example
  let 
  
 collectionRef 
  
 = 
  
 firestore 
 . 
 collection 
 ( 
 'col' 
 ); 
 // doc.foo == 'bar' && doc.baz > 0 
 let 
  
 andFilter 
  
 = 
  
 Filter 
 . 
 and 
 ( 
 Filter 
 . 
 where 
 ( 
 'foo' 
 , 
  
 '==' 
 , 
  
 'bar' 
 ), 
  
 Filter 
 . 
 where 
 ( 
 'baz' 
 , 
  
 '>' 
 , 
  
 0 
 )); 
 collectionRef 
 . 
 where 
 ( 
 andFilter 
 ). 
 get 
 (). 
 then 
 ( 
 querySnapshot 
  
 = 
>  
 { 
  
 querySnapshot 
 . 
 forEach 
 ( 
 documentSnapshot 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 `Found document at 
 ${ 
 documentSnapshot 
 . 
 ref 
 . 
 path 
 } 
 ` 
 ); 
  
 }); 
 }); 
 

or(filters)

  static 
  
 or 
 (... 
 filters 
 : 
  
 Filter 
 []) 
 : 
  
 Filter 
 ; 
 

Creates and returns a new [Filter] Filter that is a disjunction of the given Filter s. A disjunction filter includes a document if it satisfies any of the given Filter s.

The returned Filter can be applied to [Query.where()], [Filter.or()], or [Filter.and()]. When applied to a [Query] Query it requires that documents must satisfy one of the provided Filter s.

Parameter
Name
Description
filters
Filter []

Optional. The Filter s for OR operation. These must be created with calls to , , or .

Returns
Type
Description

{Filter} The created Filter .

Example
  let 
  
 collectionRef 
  
 = 
  
 firestore 
 . 
 collection 
 ( 
 'col' 
 ); 
 // doc.foo == 'bar' || doc.baz > 0 
 let 
  
 orFilter 
  
 = 
  
 Filter 
 . 
 or 
 ( 
 Filter 
 . 
 where 
 ( 
 'foo' 
 , 
  
 '==' 
 , 
  
 'bar' 
 ), 
  
 Filter 
 . 
 where 
 ( 
 'baz' 
 , 
  
 '>' 
 , 
  
 0 
 )); 
 collectionRef 
 . 
 where 
 ( 
 orFilter 
 ). 
 get 
 (). 
 then 
 ( 
 querySnapshot 
  
 = 
>  
 { 
  
 querySnapshot 
 . 
 forEach 
 ( 
 documentSnapshot 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 `Found document at 
 ${ 
 documentSnapshot 
 . 
 ref 
 . 
 path 
 } 
 ` 
 ); 
  
 }); 
 }); 
 

where(fieldPath, opStr, value)

  static 
  
 where 
 ( 
 fieldPath 
 : 
  
 string 
  
 | 
  
 firestore 
 . 
 FieldPath 
 , 
  
 opStr 
 : 
  
 firestore 
 . 
 WhereFilterOp 
 , 
  
 value 
 : 
  
 unknown 
 ) 
 : 
  
 Filter 
 ; 
 

Creates and returns a new [Filter] Filter , which can be applied to [Query.where()], [Filter.or()], or [Filter.and()]. When applied to a [Query] Query it requires that documents must contain the specified field and that its value should satisfy the relation constraint provided.

Parameters
Name
Description
fieldPath
string | FirebaseFirestore.FieldPath

The name of a property value to compare.

opStr
firestore.WhereFilterOp

A comparison operation in the form of a string. Acceptable operator strings are "<", "<=", "==", "!=", ">=", ">", "array-contains", "in", "not-in", and "array-contains-any".

value
unknown

The value to which to compare the field for inclusion in a query.

Returns
Type
Description

{Filter} The created Filter.

Example
  let 
  
 collectionRef 
  
 = 
  
 firestore 
 . 
 collection 
 ( 
 'col' 
 ); 
 collectionRef 
 . 
 where 
 ( 
 Filter 
 . 
 where 
 ( 
 'foo' 
 , 
  
 '==' 
 , 
  
 'bar' 
 )). 
 get 
 (). 
 then 
 ( 
 querySnapshot 
  
 = 
>  
 { 
  
 querySnapshot 
 . 
 forEach 
 ( 
 documentSnapshot 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 `Found document at 
 ${ 
 documentSnapshot 
 . 
 ref 
 . 
 path 
 } 
 ` 
 ); 
  
 }); 
 }); 
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: