com.mongodb
Class QueryBuilder

java.lang.Object
  extended by com.mongodb.QueryBuilder

public class QueryBuilder
extends java.lang.Object

Utility for creating DBObject queries

Author:
Julson Lim

Constructor Summary
QueryBuilder()
           
 
Method Summary
 QueryBuilder all(java.lang.Object object)
          Equivalent of the $all operand
 QueryBuilder and(java.lang.String key)
          Equivalent to QueryBuilder.put(key).
 QueryBuilder exists(java.lang.Object object)
          Equivalent of the $exists operand
 DBObject get()
          Creates a DBObject query to be used for the driver's find operations
 QueryBuilder greaterThan(java.lang.Object object)
          Equivalent to the $gt operator
 QueryBuilder greaterThanEquals(java.lang.Object object)
          Equivalent to the $gte operator
 QueryBuilder in(java.lang.Object object)
          Equivalent of the $in operand
 QueryBuilder is(java.lang.Object object)
          Equivalent of the find({key:value})
 QueryBuilder lessThan(java.lang.Object object)
          Equivalent to the $lt operand
 QueryBuilder lessThanEquals(java.lang.Object object)
          Equivalent to the $lte operand
 QueryBuilder mod(java.lang.Object object)
          Equivalent of the $mod operand
 QueryBuilder near(double x, double y)
           
 QueryBuilder near(double x, double y, double maxDistance)
           
 QueryBuilder notEquals(java.lang.Object object)
          Equivalent of the $ne operand
 QueryBuilder notIn(java.lang.Object object)
          Equivalent of the $nin operand
 QueryBuilder or(DBObject... ors)
           
 QueryBuilder put(java.lang.String key)
          Adds a new key to the query or sets an existing key to as current for chaining
 QueryBuilder regex(java.util.regex.Pattern regex)
          Passes a regular expression for a query
 QueryBuilder size(java.lang.Object object)
          Equivalent of the $size operand
static QueryBuilder start()
           
static QueryBuilder start(java.lang.String key)
          Creates a new query with a document key
 QueryBuilder withinCenter(double x, double y, double radius)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryBuilder

public QueryBuilder()
Method Detail

start

public static QueryBuilder start()

start

public static QueryBuilder start(java.lang.String key)
Creates a new query with a document key

Parameters:
key - MongoDB document key
Returns:
Returns a new QueryBuilder

put

public QueryBuilder put(java.lang.String key)
Adds a new key to the query or sets an existing key to as current for chaining

Parameters:
key - MongoDB document key
Returns:
Returns the current QueryBuilder with an appended key operand

and

public QueryBuilder and(java.lang.String key)
Equivalent to QueryBuilder.put(key). Intended for compound query chains to be more readable Example: QueryBuilder.start("a").greaterThan(1).and("b").lessThan(3)

Parameters:
key - MongoDB document key
Returns:
Returns the current QueryBuilder with an appended key operand

greaterThan

public QueryBuilder greaterThan(java.lang.Object object)
Equivalent to the $gt operator

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "greater than" query

greaterThanEquals

public QueryBuilder greaterThanEquals(java.lang.Object object)
Equivalent to the $gte operator

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "greater than or equals" query

lessThan

public QueryBuilder lessThan(java.lang.Object object)
Equivalent to the $lt operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "less than" query

lessThanEquals

public QueryBuilder lessThanEquals(java.lang.Object object)
Equivalent to the $lte operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "less than or equals" query

is

public QueryBuilder is(java.lang.Object object)
Equivalent of the find({key:value})

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended equality query

notEquals

public QueryBuilder notEquals(java.lang.Object object)
Equivalent of the $ne operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended inequality query

in

public QueryBuilder in(java.lang.Object object)
Equivalent of the $in operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "in array" query

notIn

public QueryBuilder notIn(java.lang.Object object)
Equivalent of the $nin operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "not in array" query

mod

public QueryBuilder mod(java.lang.Object object)
Equivalent of the $mod operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended modulo query

all

public QueryBuilder all(java.lang.Object object)
Equivalent of the $all operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended "matches all array contents" query

size

public QueryBuilder size(java.lang.Object object)
Equivalent of the $size operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended size operator

exists

public QueryBuilder exists(java.lang.Object object)
Equivalent of the $exists operand

Parameters:
object - Value to query
Returns:
Returns the current QueryBuilder with an appended exists operator

regex

public QueryBuilder regex(java.util.regex.Pattern regex)
Passes a regular expression for a query

Parameters:
regex - Regex pattern object
Returns:
Returns the current QueryBuilder with an appended regex query

withinCenter

public QueryBuilder withinCenter(double x,
                                 double y,
                                 double radius)

near

public QueryBuilder near(double x,
                         double y)

near

public QueryBuilder near(double x,
                         double y,
                         double maxDistance)

or

public QueryBuilder or(DBObject... ors)

get

public DBObject get()
Creates a DBObject query to be used for the driver's find operations

Returns:
Returns a DBObject query instance
Throws:
java.lang.RuntimeException - if a key does not have a matching operand