public class QueryBuilder extends Object implements DocumentAssignable
Document
s.
As an example:
import static
com.allanbank.mongodb.builder.QueryBuilder.and
import staticcom.allanbank.mongodb.builder.QueryBuilder.or
import staticcom.allanbank.mongodb.builder.QueryBuilder.not
import staticcom.allanbank.mongodb.builder.QueryBuilder.where
Document query = or( where("f").greaterThan(23).lessThan(42).and("g").lessThan(3), and( where("f").greaterThanOrEqualTo(42), not( where("g").lessThan(3) ) ) );
Constructor and Description |
---|
QueryBuilder()
Creates a new QueryBuilder.
|
Modifier and Type | Method and Description |
---|---|
static Document |
and(DocumentAssignable... criteria)
Creates a single document that is the conjunction of the criteria
provided.
|
Document |
asDocument()
Converts the object into a document.
|
Document |
build()
Construct the final query document.
|
static Document |
nor(DocumentAssignable... criteria)
Creates a single document that is the disjunction of the criteria
provided.
|
static Document |
not(DocumentAssignable... criteria)
Negate a set of criteria.
|
static Document |
or(DocumentAssignable... criteria)
Creates a single document that is the disjunction of the criteria
provided.
|
void |
reset()
Clears the builder's conditions.
|
static ConditionBuilder |
where(String field)
Start a criteria for a single conjunctions.
|
ConditionBuilder |
whereField(String fieldName)
Returns a builder for the constraints on a single field.
|
QueryBuilder |
whereJavaScript(String javaScript)
Adds an ad-hoc JavaScript condition to the query.
|
public static Document and(DocumentAssignable... criteria)
criteria
- The criteria to create a conjunction of.public static Document nor(DocumentAssignable... criteria)
criteria
- The criteria to create a disjunction of.public static Document not(DocumentAssignable... criteria)
criteria
- The criteria to negate. These will normally be
ConditionBuilder
s or Document
s.public static Document or(DocumentAssignable... criteria)
criteria
- The criteria to create a disjunction of.public static ConditionBuilder where(String field)
field
- The field to start the criteria against.ConditionBuilder
for constructing the conditions.public Document asDocument()
Returns the result of build()
.
asDocument
in interface DocumentAssignable
build()
public Document build()
public void reset()
public ConditionBuilder whereField(String fieldName)
fieldName
- The name of the field to constrain.ConditionBuilder
for creation of the conditions of the
field.public QueryBuilder whereJavaScript(String javaScript)
javaScript
- The javaScript condition to add.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.