public final class Filters extends Object
collection.find(and(eq("x", 1), lt("y", 3)));
| Modifier and Type | Method and Description |
|---|---|
static <TItem> Bson |
all(String fieldName,
Iterable<TItem> values)
Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
|
static <TItem> Bson |
all(String fieldName,
TItem... values)
Creates a filter that matches all documents where the value of a field is an array that contains all the specified values.
|
static Bson |
and(Bson... filters)
Creates a filter that performs a logical AND of the provided list of filters.
|
static Bson |
and(Iterable<Bson> filters)
Creates a filter that performs a logical AND of the provided list of filters.
|
static Bson |
elemMatch(String fieldName,
Bson filter)
Creates a filter that matches all documents containing a field that is an array where at least one member of the array matches the
given filter.
|
static <TItem> Bson |
eq(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the field name equals the specified value.
|
static Bson |
exists(String fieldName)
Creates a filter that matches all documents that contain the given field.
|
static Bson |
exists(String fieldName,
boolean exists)
Creates a filter that matches all documents that either contain or do not contain the given field, depending on the value of the
exists parameter.
|
static <TItem> Bson |
gt(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the given field is greater than the specified value.
|
static <TItem> Bson |
gte(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value.
|
static <TItem> Bson |
in(String fieldName,
Iterable<TItem> values)
Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
|
static <TItem> Bson |
in(String fieldName,
TItem... values)
Creates a filter that matches all documents where the value of a field equals any value in the list of specified values.
|
static <TItem> Bson |
lt(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the given field is less than the specified value.
|
static <TItem> Bson |
lte(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value.
|
static Bson |
mod(String fieldName,
long divisor,
long remainder)
Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder (i.e.
|
static <TItem> Bson |
ne(String fieldName,
TItem value)
Creates a filter that matches all documents where the value of the field name does not equal the specified value.
|
static <TItem> Bson |
nin(String fieldName,
Iterable<TItem> values)
Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist.
|
static <TItem> Bson |
nin(String fieldName,
TItem... values)
Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist.
|
static Bson |
nor(Bson... filters)
Creates a filter that performs a logical NOR operation on all the specified filters.
|
static Bson |
nor(Iterable<Bson> filters)
Creates a filter that performs a logical NOR operation on all the specified filters.
|
static Bson |
not(Bson filter)
Creates a filter that matches all documents that do not match the passed in filter.
|
static Bson |
or(Bson... filters)
Creates a filter that preforms a logical OR of the provided list of filters.
|
static Bson |
or(Iterable<Bson> filters)
Creates a filter that preforms a logical OR of the provided list of filters.
|
static Bson |
regex(String fieldName,
Pattern pattern)
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
options applied.
|
static Bson |
regex(String fieldName,
String pattern)
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
options applied.
|
static Bson |
regex(String fieldName,
String pattern,
String options)
Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
options applied.
|
static Bson |
size(String fieldName,
int size)
Creates a filter that matches all documents where the value of a field is an array of the specified size.
|
static Bson |
text(String search)
Creates a filter that matches all documents matching the given search term.
|
static Bson |
text(String search,
String language)
Creates a filter that matches all documents matching the given search term using the given language.
|
static Bson |
type(String fieldName,
BsonType type)
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
|
static Bson |
where(String javaScriptExpression)
Creates a filter that matches all documents for which the given expression is true.
|
public static <TItem> Bson eq(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson ne(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson gt(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson lt(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson gte(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson lte(String fieldName, TItem value)
TItem - the value typefieldName - the field namevalue - the valuepublic static <TItem> Bson in(String fieldName, TItem... values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static <TItem> Bson in(String fieldName, Iterable<TItem> values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static <TItem> Bson nin(String fieldName, TItem... values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static <TItem> Bson nin(String fieldName, Iterable<TItem> values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static Bson and(Iterable<Bson> filters)
and(eq("x", 1), lt("y", 3))
will generate a MongoDB query like:
{x : 1, y : {$lt : 3}}
filters - the list of filters to and togetherpublic static Bson and(Bson... filters)
and(eq("x", 1), lt("y", 3))
will generate a MongoDB query like:
{x : 1, y : {$lt : 3}}
filters - the list of filters to and togetherpublic static Bson or(Iterable<Bson> filters)
filters - the list of filters to and togetherpublic static Bson or(Bson... filters)
filters - the list of filters to and togetherpublic static Bson not(Bson filter)
not(eq("x", 1))
will generate a MongoDB query like:
{x : $not: {$eq : 1}}
filter - the valuepublic static Bson nor(Bson... filters)
filters - the list of valuespublic static Bson nor(Iterable<Bson> filters)
filters - the list of valuespublic static Bson exists(String fieldName)
fieldName - the field namepublic static Bson exists(String fieldName, boolean exists)
fieldName - the field nameexists - true to check for existence, false to check for absencepublic static Bson type(String fieldName, BsonType type)
fieldName - the field nametype - the BSON typepublic static Bson mod(String fieldName, long divisor, long remainder)
fieldName - the field namedivisor - the modulusremainder - the remainderpublic static Bson regex(String fieldName, String pattern)
fieldName - the field namepattern - the patternpublic static Bson regex(String fieldName, String pattern, String options)
fieldName - the field namepattern - the patternoptions - the optionspublic static Bson regex(String fieldName, Pattern pattern)
fieldName - the field namepattern - the patternpublic static Bson text(String search)
search - the search termpublic static Bson text(String search, String language)
search - the search termlanguage - the language to use for stop wordspublic static Bson where(String javaScriptExpression)
javaScriptExpression - the JavaScript expressionpublic static <TItem> Bson all(String fieldName, TItem... values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static <TItem> Bson all(String fieldName, Iterable<TItem> values)
TItem - the value typefieldName - the field namevalues - the list of valuespublic static Bson elemMatch(String fieldName, Bson filter)
fieldName - the field namefilter - the filter to apply to each element