Package dev.morphia.query.filters
Class Filters
- java.lang.Object
-
- dev.morphia.query.filters.Filters
-
public final class Filters extends Object
Defines helper methods to generate filter operations for queries.- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Filterall(String field, Object val)Matches arrays that contain all elements specified in the query.static LogicalFilterand(Filter... filters)Applies $and to a set of filtersstatic FilterbitsAllClear(String field, int bitMask)Matches numeric or binary values in which a set of bit positions all have a value of 0.static FilterbitsAllClear(String field, int[] positions)Matches numeric or binary values in which a set of bit positions all have a value of 0.static FilterbitsAllSet(String field, int bitMask)Matches numeric or binary values in which a set of bit positions all have a value of 1.static FilterbitsAllSet(String field, int[] positions)Matches numeric or binary values in which a set of bit positions all have a value of 1.static FilterbitsAnyClear(String field, Object val)Matches numeric or binary values in which any bit from a set of bit positions has a value of 0.static FilterbitsAnySet(String field, Object val)Matches numeric or binary values in which any bit from a set of bit positions has a value of 1.static Filterbox(String field, Point bottomLeft, Point upperRight)Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries.static Filtercenter(String field, Point center, double radius)Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry.static FiltercenterSphere(String field, Point center, double radius)Defines a circle for a geospatial query that uses spherical geometry.static Filtercomment(String field, Object val)Adds a comment to a query predicate.static FilterelemMatch(String field, Filter... filters)Selects documents if element in the array field matches all the specified $elemMatch conditions.static Filtereq(String field, Object val)Specifies equality condition.static Filterexists(String field)Matches documents that have the specified field.static Filterexpr(dev.morphia.aggregation.expressions.impls.Expression expression)Allows use of aggregation expressions within the query language.static FiltergeoIntersects(String field, Geometry val)Selects geometries that intersect with a GeoJSON geometry.static Filtergeometry(String field, Object val)Specifies a geometry in GeoJSON format to geospatial query operators.static GeoWithinFiltergeoWithin(String field, MultiPolygon polygon)Selects geometries within a bounding GeoJSON geometry.static GeoWithinFiltergeoWithin(String field, Polygon polygon)Selects geometries within a bounding GeoJSON geometry.static Filtergt(String field, Object val)$gt selects those documents where the value of the field is greater than the specified value.static Filtergte(String field, Object val)$gte selects the documents where the value of the field is greater than or equal to a specified value (e.g.static Filterin(String field, Iterable<?> val)The $in operator selects the documents where the value of a field equals any value in the specified array.static FilterjsonSchema(String field, Object val)Deprecated, for removal: This API element is subject to removal in a future version.usejsonSchema(Document)insteadstatic FilterjsonSchema(Document schema)Filters documents against the given JSON Schema.static Filterlt(String field, Object val)$lt selects the documents where the value of the field is less than the specified value.static Filterlte(String field, Object val)$lte selects the documents where the value of the field is less than or equal to the specified value.static FiltermaxDistance(String field, Object val)Specifies a maximum distance to limit the results of $near and $nearSphere queries.static FilterminDistance(String field, Object val)Specifies a minimum distance to limit the results of $near and $nearSphere queries.static Filtermod(String field, long divisor, long remainder)Performs a modulo operation on the value of a field and selects documents with a specified result.static Filterne(String field, Object val)$ne selects the documents where the value of the field is not equal to the specified value.static NearFilternear(String field, Point point)Specifies a point for which a geospatial query returns the documents from nearest to farthest.static NearFilternearSphere(String field, Point point)Returns geospatial objects in proximity to a point on a sphere.static Filternin(String field, Object val)$nin selects the documents where: the field value is not in the specified array or the field does not exist.static LogicalFilternor(Filter... filters)Applies $nor to a set of filtersstatic LogicalFilteror(Filter... filters)Applies $or to a set of filtersstatic Filterpolygon(String field, Point... points)Specifies a polygon to using legacy coordinate pairs for $geoWithin queries.static RegexFilterregex(String field)Selects documents where values match a specified regular expression.static Filtersize(String field, int size)Selects documents if the array field is a specified size.static TextSearchFiltertext(String textSearch)Performs text search.static Filtertype(String field, Type val)Selects documents if a field is of the specified type.static FilteruniqueDocs(String field, Object val)Deprecated.static Filterwhere(String val)Matches documents that satisfy a JavaScript expression.
-
-
-
Method Detail
-
all
public static Filter all(String field, @Nullable Object val)
Matches arrays that contain all elements specified in the query.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $all
-
and
public static LogicalFilter and(Filter... filters)
Applies $and to a set of filters- Parameters:
filters- the filters- Returns:
- the filter
- MongoDB documentation
- Query Filter: $and
-
bitsAllClear
public static Filter bitsAllClear(String field, int[] positions)
Matches numeric or binary values in which a set of bit positions all have a value of 0.- Parameters:
field- the field to checkpositions- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAllClear
-
bitsAllClear
public static Filter bitsAllClear(String field, int bitMask)
Matches numeric or binary values in which a set of bit positions all have a value of 0.- Parameters:
field- the field to checkbitMask- the numeric bitmask to use- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAllClear
-
bitsAllSet
public static Filter bitsAllSet(String field, int bitMask)
Matches numeric or binary values in which a set of bit positions all have a value of 1.- Parameters:
field- the field to checkbitMask- the numeric bitmask to use- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAllSet
-
bitsAllSet
public static Filter bitsAllSet(String field, int[] positions)
Matches numeric or binary values in which a set of bit positions all have a value of 1.- Parameters:
field- the field to checkpositions- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAllSet
-
bitsAnyClear
public static Filter bitsAnyClear(String field, Object val)
Matches numeric or binary values in which any bit from a set of bit positions has a value of 0.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAnyClear
-
bitsAnySet
public static Filter bitsAnySet(String field, Object val)
Matches numeric or binary values in which any bit from a set of bit positions has a value of 1.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $bitsAnySet
-
box
public static Filter box(String field, Point bottomLeft, Point upperRight)
Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box.- Parameters:
field- the field to checkbottomLeft- the bottom left corner of the boxupperRight- the upper right corner of the box- Returns:
- the filter
- MongoDB documentation
- Query Filter: $box
-
center
public static Filter center(String field, Point center, double radius)
Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center.- Parameters:
field- the field to checkcenter- the center point of the shaperadius- the radius of the circle- Returns:
- the filter
- MongoDB documentation
- Query Filter: $center
-
centerSphere
public static Filter centerSphere(String field, Point center, double radius)
Defines a circle for a geospatial query that uses spherical geometry. The query returns documents that are within the bounds of the circle. You can use the $centerSphere operator on both GeoJSON objects and legacy coordinate pairs.To use $centerSphere, specify an array that contains:
- The grid coordinates of the circle’s center point, and
- The circle’s radius measured in radians. To calculate radians, see Calculate Distance Using Spherical Geometry.
- Parameters:
field- the field to checkcenter- the center point of the shaperadius- the radius of the circle- Returns:
- the filter
- MongoDB documentation
- Query Filter: $centerSphere
-
comment
public static Filter comment(String field, Object val)
Adds a comment to a query predicate.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $comment
-
elemMatch
public static Filter elemMatch(String field, Filter... filters)
Selects documents if element in the array field matches all the specified $elemMatch conditions.- Parameters:
field- the field to checkfilters- the filters to evaluate against- Returns:
- the filter
- MongoDB documentation
- Query Filter: $elemMatch
-
eq
public static Filter eq(String field, @Nullable Object val)
Specifies equality condition. The $eq operator matches documents where the value of a field equals the specified value.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $eq
-
exists
public static Filter exists(String field)
Matches documents that have the specified field.- Parameters:
field- the field to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $exists
-
expr
public static Filter expr(dev.morphia.aggregation.expressions.impls.Expression expression)
Allows use of aggregation expressions within the query language.- Parameters:
expression- the expression to evaluate- Returns:
- the filter
- MongoDB documentation
- Query Filter: $expr
-
geoIntersects
public static Filter geoIntersects(String field, Geometry val)
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $geoIntersects
-
geoWithin
public static GeoWithinFilter geoWithin(String field, Polygon polygon)
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.- Parameters:
field- the field to checkpolygon- the polygon to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $geoWithin
-
geoWithin
public static GeoWithinFilter geoWithin(String field, MultiPolygon polygon)
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.- Parameters:
field- the field to checkpolygon- the polygon to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $geoWithin
-
geometry
public static Filter geometry(String field, Object val)
Specifies a geometry in GeoJSON format to geospatial query operators.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $geometry
-
gt
public static Filter gt(String field, Object val)
$gt selects those documents where the value of the field is greater than the specified value.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $gt
-
gte
public static Filter gte(String field, Object val)
$gte selects the documents where the value of the field is greater than or equal to a specified value (e.g. value.)- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $gte
-
in
public static Filter in(String field, Iterable<?> val)
The $in operator selects the documents where the value of a field equals any value in the specified array.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $in
-
jsonSchema
@Deprecated(forRemoval=true) public static Filter jsonSchema(String field, Object val)
Deprecated, for removal: This API element is subject to removal in a future version.usejsonSchema(Document)insteadFilters documents against the given JSON Schema.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $jsonSchema
-
jsonSchema
public static Filter jsonSchema(Document schema)
Filters documents against the given JSON Schema.- Parameters:
schema- the schema to use- Returns:
- the filter
- Since:
- 2.1
- MongoDB documentation
- Query Filter: $jsonSchema
-
lt
public static Filter lt(String field, Object val)
$lt selects the documents where the value of the field is less than the specified value.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $lt
-
lte
public static Filter lte(String field, Object val)
$lte selects the documents where the value of the field is less than or equal to the specified value.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $lte
-
maxDistance
public static Filter maxDistance(String field, Object val)
Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $maxDistance
-
minDistance
public static Filter minDistance(String field, Object val)
Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $minDistance
-
mod
public static Filter mod(String field, long divisor, long remainder)
Performs a modulo operation on the value of a field and selects documents with a specified result.- Parameters:
field- the field to checkdivisor- the value to divide byremainder- the remainder to check for- Returns:
- the filter
- MongoDB documentation
- Query Filter: $mod
-
ne
public static Filter ne(String field, Object val)
$ne selects the documents where the value of the field is not equal to the specified value. This includes documents that do not contain the field.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $ne
-
near
public static NearFilter near(String field, Point point)
Specifies a point for which a geospatial query returns the documents from nearest to farthest. The $near operator can specify either a GeoJSON point or legacy coordinate point.This requires a geospatial index.
- Parameters:
field- the field to checkpoint- the point to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $near
-
nearSphere
public static NearFilter nearSphere(String field, Point point)
Returns geospatial objects in proximity to a point on a sphere.Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
- Parameters:
field- the field to checkpoint- the point to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $nearSphere
-
nin
public static Filter nin(String field, Object val)
$nin selects the documents where:- the field value is not in the specified array or
- the field does not exist.
- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $nin
-
nor
public static LogicalFilter nor(Filter... filters)
Applies $nor to a set of filters- Parameters:
filters- the filters- Returns:
- the filter
- MongoDB documentation
- Query Filter: $nor
-
or
public static LogicalFilter or(Filter... filters)
Applies $or to a set of filters- Parameters:
filters- the filters- Returns:
- the filter
- MongoDB documentation
- Query Filter: $or
-
polygon
public static Filter polygon(String field, Point... points)
Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center.- Parameters:
field- the field to checkpoints- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $polygon
-
regex
public static RegexFilter regex(String field)
Selects documents where values match a specified regular expression.- Parameters:
field- the field to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $regex
-
size
public static Filter size(String field, int size)
Selects documents if the array field is a specified size.- Parameters:
field- the field to checksize- the size to check against- Returns:
- the filter
- MongoDB documentation
- Query Filter: $size
-
text
public static TextSearchFilter text(String textSearch)
Performs text search.- Parameters:
textSearch- the text to search for- Returns:
- the filter
- MongoDB documentation
- Query Filter: $text
-
type
public static Filter type(String field, Type val)
Selects documents if a field is of the specified type.- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $type
-
uniqueDocs
public static Filter uniqueDocs(String field, Object val)
Deprecated. Modifies a $geoWithin and $near queries to ensure that even if a document matches the query multiple times, the query returns the document once.}- Parameters:
field- the field to checkval- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $uniqueDocs
-
where
public static Filter where(String val)
Matches documents that satisfy a JavaScript expression.- Parameters:
val- the value to check- Returns:
- the filter
- MongoDB documentation
- Query Filter: $where
-
-