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/firestoreMethods
and(filters)
static and(...filters: Filter[]): Filter;
Creates and returns a new [Filter]Filter that is a conjunction of the given Filters. A conjunction filter includes a document if it satisfies all of the given Filters.
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 Filters.
Parameter | |
---|---|
Name | Description |
filters |
Filter[]
Optional. The Filters for AND operation. These must be created with calls to , , or . |
Returns | |
---|---|
Type | Description |
Filter | {Filter} The created Filter. |
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 Filters. A disjunction filter includes a document if it satisfies any of the given Filters.
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 Filters.
Parameter | |
---|---|
Name | Description |
filters |
Filter[]
Optional. The Filters for OR operation. These must be created with calls to , , or . |
Returns | |
---|---|
Type | Description |
Filter | {Filter} The created Filter. |
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 | {Filter} The created Filter. |
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}`);
});
});