Package com.mongodb
Class QueryBuilder
- java.lang.Object
 - 
- com.mongodb.QueryBuilder
 
 
- 
- 
Constructor Summary
Constructors Constructor Description QueryBuilder()Creates a builder with an empty query 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryBuilderall(Object object)Equivalent of the $all operandQueryBuilderand(DBObject... ands)Equivalent to an $and operandQueryBuilderand(String key)Equivalent toQueryBuilder.put(key).QueryBuilderelemMatch(DBObject match)Equivalent to the $elemMatch operandQueryBuilderexists(Object object)Equivalent of the $exists operandDBObjectget()Creates aDBObjectquery to be used for the driver's find operationsQueryBuildergreaterThan(Object object)Equivalent to the $gt operatorQueryBuildergreaterThanEquals(Object object)Equivalent to the $gte operatorQueryBuilderin(Object object)Equivalent of the $in operandQueryBuilderis(Object object)Equivalent of the find({key:value})QueryBuilderlessThan(Object object)Equivalent to the $lt operandQueryBuilderlessThanEquals(Object object)Equivalent to the $lte operandQueryBuildermod(Object object)Equivalent of the $mod operandQueryBuildernear(double x, double y)Equivalent of the $near operandQueryBuildernear(double x, double y, double maxDistance)Equivalent of the $near operandQueryBuildernearSphere(double longitude, double latitude)Equivalent of the $nearSphere operandQueryBuildernearSphere(double longitude, double latitude, double maxDistance)Equivalent of the $nearSphere operandQueryBuildernot()Equivalent to $not meta operator.QueryBuildernotEquals(Object object)Equivalent of the $ne operandQueryBuildernotIn(Object object)Equivalent of the $nin operandQueryBuilderor(DBObject... ors)Equivalent to an $or operandQueryBuilderput(String key)Adds a new key to the query if not present yet.QueryBuilderregex(Pattern regex)Passes a regular expression for a queryQueryBuildersize(Object object)Equivalent of the $size operandstatic QueryBuilderstart()Returns a new QueryBuilder.static QueryBuilderstart(String key)Creates a new query with a document keyQueryBuildertext(String search)Equivalent to a $text operand.QueryBuildertext(String search, String language)Equivalent to a $text operand.QueryBuilderwithinBox(double x, double y, double x2, double y2)Equivalent to a $within operand, based on a bounding box using represented by two cornersQueryBuilderwithinCenter(double x, double y, double radius)Equivalent of the $within operand, used for geospatial operationQueryBuilderwithinCenterSphere(double longitude, double latitude, double maxDistance)Equivalent of the $centerSphere operand mostly intended for queries up to a few hundred miles or km.QueryBuilderwithinPolygon(List<Double[]> points)Equivalent to a $within operand, based on a bounding polygon represented by an array of points 
 - 
 
- 
- 
Method Detail
- 
start
public static QueryBuilder start()
Returns a new QueryBuilder.- Returns:
 - a builder
 
 
- 
start
public static QueryBuilder start(String key)
Creates a new query with a document key- Parameters:
 key- MongoDB document key- Returns:
 this
 
- 
put
public QueryBuilder put(String key)
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
public QueryBuilder and(String key)
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
public QueryBuilder greaterThan(Object object)
Equivalent to the $gt operator- Parameters:
 object- Value to query- Returns:
 this
 
- 
greaterThanEquals
public QueryBuilder greaterThanEquals(Object object)
Equivalent to the $gte operator- Parameters:
 object- Value to query- Returns:
 this
 
- 
lessThan
public QueryBuilder lessThan(Object object)
Equivalent to the $lt operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
lessThanEquals
public QueryBuilder lessThanEquals(Object object)
Equivalent to the $lte operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
is
public QueryBuilder is(Object object)
Equivalent of the find({key:value})- Parameters:
 object- Value to query- Returns:
 this
 
- 
notEquals
public QueryBuilder notEquals(Object object)
Equivalent of the $ne operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
in
public QueryBuilder in(Object object)
Equivalent of the $in operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
notIn
public QueryBuilder notIn(Object object)
Equivalent of the $nin operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
mod
public QueryBuilder mod(Object object)
Equivalent of the $mod operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
all
public QueryBuilder all(Object object)
Equivalent of the $all operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
size
public QueryBuilder size(Object object)
Equivalent of the $size operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
exists
public QueryBuilder exists(Object object)
Equivalent of the $exists operand- Parameters:
 object- Value to query- Returns:
 this
 
- 
regex
public QueryBuilder regex(Pattern regex)
Passes a regular expression for a query- Parameters:
 regex- Regex pattern object- Returns:
 this
 
- 
elemMatch
public QueryBuilder elemMatch(DBObject match)
Equivalent to the $elemMatch operand- Parameters:
 match- the object to match- Returns:
 this
 
- 
withinCenter
public QueryBuilder withinCenter(double x, double y, double radius)
Equivalent of the $within operand, used for geospatial operation- Parameters:
 x- x coordinatey- y coordinateradius- radius- Returns:
 this
 
- 
near
public QueryBuilder near(double x, double y)
Equivalent of the $near operand- Parameters:
 x- x coordinatey- y coordinate- Returns:
 this
 
- 
near
public QueryBuilder near(double x, double y, double maxDistance)
Equivalent of the $near operand- Parameters:
 x- x coordinatey- y coordinatemaxDistance- max distance- Returns:
 this
 
- 
nearSphere
public QueryBuilder nearSphere(double longitude, double latitude)
Equivalent of the $nearSphere operand- Parameters:
 longitude- coordinate in decimal degreeslatitude- coordinate in decimal degrees- Returns:
 this
 
- 
nearSphere
public QueryBuilder nearSphere(double longitude, double latitude, double maxDistance)
Equivalent of the $nearSphere operand- Parameters:
 longitude- coordinate in decimal degreeslatitude- coordinate in decimal degreesmaxDistance- max spherical distance- Returns:
 this
 
- 
withinCenterSphere
public QueryBuilder withinCenterSphere(double longitude, double latitude, double maxDistance)
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
public QueryBuilder withinBox(double x, double y, double x2, double y2)
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
public QueryBuilder withinPolygon(List<Double[]> points)
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
public QueryBuilder text(String search)
Equivalent to a $text operand.- Parameters:
 search- the search terms to apply to the text index.- Returns:
 this- Since server release
 - 2.6
 
 
- 
text
public QueryBuilder text(String search, @Nullable String language)
Equivalent to a $text operand.- Parameters:
 search- the search terms to apply to the text index.language- the language to use.- Returns:
 this- Since server release
 - 2.6
 
 
- 
not
public QueryBuilder 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
public QueryBuilder or(DBObject... ors)
Equivalent to an $or operand- Parameters:
 ors- the list of conditions to or together- Returns:
 this
 
- 
and
public QueryBuilder and(DBObject... ands)
Equivalent to an $and operand- Parameters:
 ands- the list of conditions to and together- Returns:
 this
 
- 
get
public DBObject get()
Creates aDBObjectquery to be used for the driver's find operations- Returns:
 this- Throws:
 RuntimeException- if a key does not have a matching operand
 
 - 
 
 -