public final class Filters extends Object
collection.find(and(eq("x", 1), lt("y", 3)));
Modifier and Type | Method | 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(Iterable<Bson> filters) |
Creates a filter that performs a logical AND of the provided list of filters.
|
static Bson |
and(Bson... filters) |
Creates a filter that performs a logical AND of the provided list of filters.
|
static Bson |
bitsAllClear(String fieldName,
long bitmask) |
Creates a filter that matches all documents where all of the bit positions are clear in the field.
|
static Bson |
bitsAllSet(String fieldName,
long bitmask) |
Creates a filter that matches all documents where all of the bit positions are set in the field.
|
static Bson |
bitsAnyClear(String fieldName,
long bitmask) |
Creates a filter that matches all documents where any of the bit positions are clear in the field.
|
static Bson |
bitsAnySet(String fieldName,
long bitmask) |
Creates a filter that matches all documents where any of the bit positions are set in the field.
|
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 <TItem> Bson |
eq(TItem value) |
Creates a filter that matches all documents where the value of _id field 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 <TExpression> |
expr(TExpression expression) |
Allows the use of aggregation expressions within the query language.
|
static Bson |
geoIntersects(String fieldName,
Geometry geometry) |
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
|
static Bson |
geoIntersects(String fieldName,
Bson geometry) |
Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape.
|
static Bson |
geoWithin(String fieldName,
Geometry geometry) |
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
|
static Bson |
geoWithin(String fieldName,
Bson geometry) |
Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape.
|
static Bson |
geoWithinBox(String fieldName,
double lowerLeftX,
double lowerLeftY,
double upperRightX,
double upperRightY) |
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
box.
|
static Bson |
geoWithinCenter(String fieldName,
double x,
double y,
double radius) |
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
circle.
|
static Bson |
geoWithinCenterSphere(String fieldName,
double x,
double y,
double radius) |
Creates a filter that matches all documents containing a field with geospatial data (GeoJSON or legacy coordinate pairs) that exist
entirely within the specified circle, using spherical geometry.
|
static Bson |
geoWithinPolygon(String fieldName,
List<List<Double>> points) |
Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
polygon.
|
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 Bson |
jsonSchema(Bson schema) |
Creates a filter that matches all documents that validate against the given JSON schema document.
|
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 Bson |
near(String fieldName,
double x,
double y,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point.
|
static Bson |
near(String fieldName,
Point geometry,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
|
static Bson |
near(String fieldName,
Bson geometry,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point.
|
static Bson |
nearSphere(String fieldName,
double x,
double y,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified point using
spherical geometry.
|
static Bson |
nearSphere(String fieldName,
Point geometry,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using
spherical geometry.
|
static Bson |
nearSphere(String fieldName,
Bson geometry,
Double maxDistance,
Double minDistance) |
Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point using
spherical geometry.
|
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(Iterable<Bson> filters) |
Creates a filter that performs a logical NOR operation on all the specified filters.
|
static Bson |
nor(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(Iterable<Bson> filters) |
Creates a filter that preforms a logical OR of the provided list of filters.
|
static Bson |
or(Bson... filters) |
Creates a filter that preforms a logical OR of the provided list of filters.
|
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 |
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 |
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,
TextSearchOptions textSearchOptions) |
Creates a filter that matches all documents matching the given the search term with the given text search options.
|
static Bson |
text(String search,
String language) |
Deprecated.
|
static Bson |
type(String fieldName,
String type) |
Creates a filter that matches all documents where the value of the field is of the specified BSON type.
|
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(@Nullable TItem value)
TItem
- the value typevalue
- the value, which may be nullpublic static <TItem> Bson eq(String fieldName, @Nullable TItem value)
TItem
- the value typefieldName
- the field namevalue
- the value, which may be nullpublic static <TItem> Bson ne(String fieldName, @Nullable TItem value)
TItem
- the value typefieldName
- the field namevalue
- the value, which may be nullpublic 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)
will generate a MongoDB query like:and(eq("x", 1), lt("y", 3))
{x : 1, y : {$lt : 3}}
filters
- the list of filters to and togetherpublic static Bson and(Bson... filters)
will generate a MongoDB query like:and(eq("x", 1), lt("y", 3))
{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)
will generate a MongoDB query like:not(eq("x", 1))
{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 type(String fieldName, String type)
fieldName
- the field nametype
- the string representation of 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, @Nullable 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 term@Deprecated public static Bson text(String search, String language)
text(String, TextSearchOptions)
search
- the search termlanguage
- the language to use for stop wordspublic static Bson text(String search, TextSearchOptions textSearchOptions)
search
- the search termtextSearchOptions
- the text search options to usepublic static Bson where(String javaScriptExpression)
javaScriptExpression
- the JavaScript expressionpublic static <TExpression> Bson expr(TExpression expression)
public 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 elementpublic static Bson size(String fieldName, int size)
fieldName
- the field namesize
- the size of the arraypublic static Bson bitsAllClear(String fieldName, long bitmask)
fieldName
- the field namebitmask
- the bitmaskpublic static Bson bitsAllSet(String fieldName, long bitmask)
fieldName
- the field namebitmask
- the bitmaskpublic static Bson bitsAnyClear(String fieldName, long bitmask)
fieldName
- the field namebitmask
- the bitmaskpublic static Bson bitsAnySet(String fieldName, long bitmask)
fieldName
- the field namebitmask
- the bitmaskpublic static Bson geoWithin(String fieldName, Geometry geometry)
fieldName
- the field namegeometry
- the bounding GeoJSON geometry objectpublic static Bson geoWithin(String fieldName, Bson geometry)
fieldName
- the field namegeometry
- the bounding GeoJSON geometry objectpublic static Bson geoWithinBox(String fieldName, double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY)
fieldName
- the field namelowerLeftX
- the lower left x coordinate of the boxlowerLeftY
- the lower left y coordinate of the boxupperRightX
- the upper left x coordinate of the boxupperRightY
- the upper left y coordinate of the boxpublic static Bson geoWithinPolygon(String fieldName, List<List<Double>> points)
fieldName
- the field namepoints
- a list of pairs of x, y coordinates. Any extra dimensions are ignoredpublic static Bson geoWithinCenter(String fieldName, double x, double y, double radius)
fieldName
- the field namex
- the x coordinate of the circley
- the y coordinate of the circleradius
- the radius of the circle, as measured in the units used by the coordinate systempublic static Bson geoWithinCenterSphere(String fieldName, double x, double y, double radius)
fieldName
- the field namex
- the x coordinate of the circley
- the y coordinate of the circleradius
- the radius of the circle, in radianspublic static Bson geoIntersects(String fieldName, Bson geometry)
fieldName
- the field namegeometry
- the bounding GeoJSON geometry objectpublic static Bson geoIntersects(String fieldName, Geometry geometry)
fieldName
- the field namegeometry
- the bounding GeoJSON geometry objectpublic static Bson near(String fieldName, Point geometry, Double maxDistance, Double minDistance)
public static Bson near(String fieldName, Bson geometry, Double maxDistance, Double minDistance)
public static Bson near(String fieldName, double x, double y, Double maxDistance, Double minDistance)
public static Bson nearSphere(String fieldName, Point geometry, Double maxDistance, Double minDistance)
public static Bson nearSphere(String fieldName, Bson geometry, Double maxDistance, Double minDistance)
public static Bson nearSphere(String fieldName, double x, double y, Double maxDistance, Double minDistance)
public static Bson jsonSchema(Bson schema)
schema
- the JSON schema to validate against