Filter

Filter

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

Constructor

new Filter()

Methods

(static) and(…filters) → {Filter}

Creates and returns a new 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 it requires that documents must satisfy one of the provided Filters.

Parameters:
Name Type Attributes Description
filters Filter <repeatable>

Optional. The Filters for AND operation. These must be created with calls to Filter#where, Filter#or, or Filter#and.

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}`);
  });
});
```

(static) or(…filters) → {Filter}

Creates and returns a new 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 it requires that documents must satisfy one of the provided Filters.

Parameters:
Name Type Attributes Description
filters Filter <repeatable>

Optional. The Filters for OR operation. These must be created with calls to Filter#where, Filter#or, or Filter#and.

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}`);
  });
});
```

(static) where(fieldPath, opStr, value) → {Filter}

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

Parameters:
Name Type Description
fieldPath string | FieldPath

The name of a property value to compare.

opStr string

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

value *

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}`);
  });
});
```