Skip to main content

MongoFilters

Definition of the filters in Bson that are used in MongoDB collection operations.


all​


all(fieldName: string, values: java.lang.Object[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the array field contains all the given values.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesjava.lang.Object[]Values that the array must contain.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


all(fieldName: string, values: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the array field contains all the given values.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


and​


and(filters: org.bson.conversions.Bson[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where all the given conditions are true (logical AND).

Attributes​
NAMETYPEDESCRIPTION
filtersorg.bson.conversions.Bson[]Filters to combine with logical AND.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


and(filters: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where all the given conditions are true (logical AND).

Attributes​
NAMETYPEDESCRIPTION
filtersValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


empty​


empty() : org.bson.conversions.Bson​

Description​

Creates an empty filter that matches all documents in the collection.

Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


eq​


eq(value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value equals the specified value.

Attributes​
NAMETYPEDESCRIPTION
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


eq(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field equals the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


exists​


exists(fieldName: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the specified field exists.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


exists(fieldName: string, exists: boolean) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the specified field exists or does not exist, according to the given flag.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
existsbooleanTrue to check if the field exists, false to check if it does not exist.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


gt​


gt(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field is greater than the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


gte​


gte(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field is greater than or equal to the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


in​


in(fieldName: string, values: java.lang.Object[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field matches any of the given values.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesjava.lang.Object[]Values to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


in(fieldName: string, values: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field matches any of the given values in the iterable.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


lt​


lt(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field is less than the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


lte​


lte(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field is less than or equal to the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


mod​


mod(fieldName: string, divisor: long, remainder: long) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder (i.e. perform a modulo operation to select documents).

How To Use​
_mongo.filters().mod('quantity', 5, 2);
Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
divisorlongThe modulus of the operation.
remainderlongThe remainder of the operation.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


ne​


ne(fieldName: string, value: java.lang.Object) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field does not equal the given value.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuejava.lang.ObjectValue to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


nin​


nin(fieldName: string, values: java.lang.Object[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field does not match any of the given values.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesjava.lang.Object[]Values to compare.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


nin(fieldName: string, values: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field does not match any of the given values in the iterable.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
valuesValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


nor​


nor(filters: org.bson.conversions.Bson[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where none of the given conditions are true (logical NOR).

Attributes​
NAMETYPEDESCRIPTION
filtersorg.bson.conversions.Bson[]Filters to combine with logical NOR.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


nor(filters: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where none of the given conditions are true (logical NOR).

Attributes​
NAMETYPEDESCRIPTION
filtersValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


not​


not(filter: org.bson.conversions.Bson) : org.bson.conversions.Bson​

Description​

Creates a filter that negates the given filter (logical NOT).

Attributes​
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonFilter to negate.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


or​


or(filters: org.bson.conversions.Bson[]) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where at least one of the given conditions is true (logical OR).

Attributes​
NAMETYPEDESCRIPTION
filtersorg.bson.conversions.Bson[]Filters to combine with logical OR.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


or(filters: Values | DataSchema | java.lang.Iterable) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where at least one of the given conditions is true (logical OR).

Attributes​
NAMETYPEDESCRIPTION
filtersValues | DataSchemajava.lang.Iterable
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


regex​


regex(fieldName: string, pattern: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the field matches the given regular expression pattern.

How To Use​
_mongo.filters().regex('fieldName', 'regex');
Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
patternstringRegular expression.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


regex(fieldName: string, pattern: string, options: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given options applied.

How To Use​
_mongo.filters().regex('fieldName', 'regex', 'i');
Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
patternstringRegular expression.
optionsstringRegex options.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


regex(fieldName: string, pattern: java.util.regex.Pattern) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of the specified field matches the given regular expression pattern.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
patternjava.util.regex.PatternRegular expression pattern.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


size​


size(fieldName: string, size: int) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the value of a field is an array of the specified size.

How To Use​
_mongo.filters().size('fieldName', '3');
Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
sizeintSize of the array.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


text​


text(search: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents for which the given text search expression matches.

Attributes​
NAMETYPEDESCRIPTION
searchstringText to search for.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


text(search: string, textSearchOptions: com.mongodb.client.model.TextSearchOptions) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents for which the given text search expression matches, with the specified text search options.

Attributes​
NAMETYPEDESCRIPTION
searchstringText to search for.
textSearchOptionscom.mongodb.client.model.TextSearchOptionsText search options.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


type​


type(fieldName: string, type: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the specified field is of the type indicated by the string.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
typestringField type as string.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


type(fieldName: string, type: org.bson.BsonType) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents where the specified field is of the given BsonType.

Attributes​
NAMETYPEDESCRIPTION
fieldNamestringDocument field name.
typeorg.bson.BsonTypeBsonType of the field.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.


where​


where(javaScriptExpression: string) : org.bson.conversions.Bson​

Description​

Creates a filter that matches all documents for which the given expression is true.

How To Use​
_mongo.filters().where('javascript-expression');
Attributes​
NAMETYPEDESCRIPTION
javaScriptExpressionstringJavaScript expression.
Return​

( org.bson.conversions.Bson )

Returns a filter in Bson format.