Package com.mongodb
Class QueryBuilder
java.lang.Object
com.mongodb.QueryBuilder
Utility for creating DBObject queries
- MongoDB documentation
- Querying
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionEquivalent of the $all operandEquivalent to an $and operandEquivalent toQueryBuilder.put(key)
.Equivalent to the $elemMatch operandEquivalent of the $exists operandget()
Creates aDBObject
query to be used for the driver's find operationsgreaterThan
(Object object) Equivalent to the $gt operatorgreaterThanEquals
(Object object) Equivalent to the $gte operatorEquivalent of the $in operandEquivalent of the find({key:value})Equivalent to the $lt operandlessThanEquals
(Object object) Equivalent to the $lte operandEquivalent of the $mod operandnear
(double x, double y) Equivalent of the $near operandnear
(double x, double y, double maxDistance) Equivalent of the $near operandnearSphere
(double longitude, double latitude) Equivalent of the $nearSphere operandnearSphere
(double longitude, double latitude, double maxDistance) Equivalent of the $nearSphere operandnot()
Equivalent to $not meta operator.Equivalent of the $ne operandEquivalent of the $nin operandEquivalent to an $or operandAdds a new key to the query if not present yet.Passes a regular expression for a queryEquivalent of the $size operandstatic QueryBuilder
start()
Returns a new QueryBuilder.static QueryBuilder
Creates a new query with a document keyEquivalent to a $text operand.Equivalent to a $text operand.withinBox
(double x, double y, double x2, double y2) Equivalent to a $within operand, based on a bounding box using represented by two cornerswithinCenter
(double x, double y, double radius) Equivalent of the $within operand, used for geospatial operationwithinCenterSphere
(double longitude, double latitude, double maxDistance) Equivalent of the $centerSphere operand mostly intended for queries up to a few hundred miles or km.withinPolygon
(List<Double[]> points) Equivalent to a $within operand, based on a bounding polygon represented by an array of points
-
Constructor Details
-
QueryBuilder
public QueryBuilder()Creates a builder with an empty query
-
-
Method Details
-
start
Returns a new QueryBuilder.- Returns:
- a builder
-
start
Creates a new query with a document key- Parameters:
key
- MongoDB document key- Returns:
this
-
put
Adds a new key to the query if not present yet. Sets this key as the current key.- Parameters:
key
- MongoDB document key- Returns:
this
-
and
Equivalent toQueryBuilder.put(key)
. Intended for compound query chains to be more readable, e.g.QueryBuilder.start("a").greaterThan(1).and("b").lessThan(3)
- Parameters:
key
- MongoDB document key- Returns:
this
-
greaterThan
Equivalent to the $gt operator- Parameters:
object
- Value to query- Returns:
this
-
greaterThanEquals
Equivalent to the $gte operator- Parameters:
object
- Value to query- Returns:
this
-
lessThan
Equivalent to the $lt operand- Parameters:
object
- Value to query- Returns:
this
-
lessThanEquals
Equivalent to the $lte operand- Parameters:
object
- Value to query- Returns:
this
-
is
Equivalent of the find({key:value})- Parameters:
object
- Value to query- Returns:
this
-
notEquals
Equivalent of the $ne operand- Parameters:
object
- Value to query- Returns:
this
-
in
Equivalent of the $in operand- Parameters:
object
- Value to query- Returns:
this
-
notIn
Equivalent of the $nin operand- Parameters:
object
- Value to query- Returns:
this
-
mod
Equivalent of the $mod operand- Parameters:
object
- Value to query- Returns:
this
-
all
Equivalent of the $all operand- Parameters:
object
- Value to query- Returns:
this
-
size
Equivalent of the $size operand- Parameters:
object
- Value to query- Returns:
this
-
exists
Equivalent of the $exists operand- Parameters:
object
- Value to query- Returns:
this
-
regex
Passes a regular expression for a query- Parameters:
regex
- Regex pattern object- Returns:
this
-
elemMatch
Equivalent to the $elemMatch operand- Parameters:
match
- the object to match- Returns:
this
-
withinCenter
Equivalent of the $within operand, used for geospatial operation- Parameters:
x
- x coordinatey
- y coordinateradius
- radius- Returns:
this
-
near
Equivalent of the $near operand- Parameters:
x
- x coordinatey
- y coordinate- Returns:
this
-
near
Equivalent of the $near operand- Parameters:
x
- x coordinatey
- y coordinatemaxDistance
- max distance- Returns:
this
-
nearSphere
Equivalent of the $nearSphere operand- Parameters:
longitude
- coordinate in decimal degreeslatitude
- coordinate in decimal degrees- Returns:
this
-
nearSphere
Equivalent of the $nearSphere operand- Parameters:
longitude
- coordinate in decimal degreeslatitude
- coordinate in decimal degreesmaxDistance
- max spherical distance- Returns:
this
-
withinCenterSphere
Equivalent of the $centerSphere operand mostly intended for queries up to a few hundred miles or km.- Parameters:
longitude
- coordinate in decimal degreeslatitude
- coordinate in decimal degreesmaxDistance
- max spherical distance- Returns:
this
-
withinBox
Equivalent to a $within operand, based on a bounding box using represented by two corners- Parameters:
x
- the x coordinate of the first box corner.y
- the y coordinate of the first box corner.x2
- the x coordinate of the second box corner.y2
- the y coordinate of the second box corner.- Returns:
this
-
withinPolygon
Equivalent to a $within operand, based on a bounding polygon represented by an array of points- Parameters:
points
- an array of Double[] defining the vertices of the search area- Returns:
this
-
text
Equivalent to a $text operand.- Parameters:
search
- the search terms to apply to the text index.- Returns:
this
-
text
Equivalent to a $text operand.- Parameters:
search
- the search terms to apply to the text index.language
- the language to use.- Returns:
this
-
not
Equivalent to $not meta operator. Must be followed by an operand, not a value, e.g.QueryBuilder.start("val").not().mod(Arrays.asList(10, 1))
- Returns:
this
-
or
Equivalent to an $or operand- Parameters:
ors
- the list of conditions to or together- Returns:
this
-
and
Equivalent to an $and operand- Parameters:
ands
- the list of conditions to and together- Returns:
this
-
get
Creates aDBObject
query to be used for the driver's find operations- Returns:
this
- Throws:
RuntimeException
- if a key does not have a matching operand
-