public final class Expressions extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ADD
The "$add" operator token
|
static String |
ALL_ELEMENTS_TRUE
The "$allElementsTrue" operator token
|
static String |
AND
The "$and" operator token
|
static String |
ANY_ELEMENT_TRUE
The "$anyElementTrue" operator token
|
static String |
COMPARE
The "$cmp" operator token
|
static String |
CONCATENATE
The "$concat" operator token
|
static String |
CONDITION
The "$cond" operator token
|
static String |
DAY_OF_MONTH
The "$dayOfMonth" operator token
|
static String |
DAY_OF_WEEK
The "$dayOfWeek" operator token
|
static String |
DAY_OF_YEAR
The "$dayOfYear" operator token
|
static String |
DIVIDE
The "$divide" operator token
|
static String |
EQUAL
The "$eq" operator token
|
static String |
GREATER_THAN
The "$gt" operator token
|
static String |
GREATER_THAN_OR_EQUAL
The "$gte" operator token
|
static String |
HOUR
The "$hour" operator token
|
static String |
IF_NULL
The "$ifNull" operator token
|
static String |
LESS_THAN
The "$lt" operator token
|
static String |
LESS_THAN_OR_EQUAL
The "$lte" operator token
|
static String |
LITERAL
The "$literal" operator token
|
static String |
MILLISECOND
The "$millisecond" operator token
|
static String |
MINUTE
The "$minute" operator token
|
static String |
MODULO
The "$mod" operator token
|
static String |
MONTH
The "$month" operator token
|
static String |
MULTIPLY
The "$multiply" operator token
|
static String |
NOT
The "$not" operator token
|
static String |
NOT_EQUAL
The "$ne" operator token
|
static String |
OR
The "$or" operator token
|
static String |
SECOND
The "$second" operator token
|
static String |
SET_DIFFERENCE
The "$setDifference" operator token
|
static String |
SET_EQUALS
The "$setEquals" operator token
|
static String |
SET_INTERSECTION
The "$setIntersection" operator token
|
static String |
SET_IS_SUBSET
The "$setIsSubset" operator token
|
static String |
SET_UNION
The "$setUnion" operator token
|
static String |
SIZE
The "$size" operator token
|
static String |
STRING_CASE_INSENSITIVE_COMPARE
The "$strcasecmp" operator token
|
static String |
SUB_STRING
The "$substr" operator token
|
static String |
SUBTRACT
The "$subtract" operator token
|
static String |
TO_LOWER
The "$toLower" operator token
|
static String |
TO_UPPER
The "$toUpper" operator token
|
static String |
WEEK
The "$week" operator token
|
static String |
YEAR
The "$year" operator token
|
Modifier and Type | Method and Description |
---|---|
static NaryExpression |
add(Expression... expressions)
Returns an
NaryExpression "$add" expression. |
static UnaryExpression |
allElementsTrue(Expression expression)
Returns a
UnaryExpression "$allElementsTrue" expression. |
static NaryExpression |
and(Expression... expressions)
Returns an
NaryExpression "$and" expression. |
static UnaryExpression |
anyElementTrue(Expression expression)
Returns a
UnaryExpression "$anyElementTrue" expression. |
static NaryExpression |
cmp(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$cmp" expression. |
static NaryExpression |
concatenate(Expression... expression)
Returns a
NaryExpression "$concat" expression. |
static NaryExpression |
cond(Expression test,
Expression trueResult,
Expression falseResult)
Returns a
NaryExpression "$cond" expression. |
static Constant |
constant(boolean value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(Date value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(double value)
Returns a
Constant expression with the provided value. |
static Expression |
constant(Element element)
Returns a
Constant expression wrapping the provided
element. |
static Constant |
constant(int value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(long value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(ObjectId value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(Pattern value)
Returns a
Constant expression with the provided value. |
static Constant |
constant(String value)
Returns a
Constant expression with the provided value. |
static Constant |
constantMongoTimestamp(long value)
Returns a
Constant expression with the provided value. |
static Constant |
constantTimestamp(long value)
Returns a
Constant expression with the provided value. |
static UnaryExpression |
dayOfMonth(Expression expression)
Returns a
UnaryExpression "$dayOfMonth" expression. |
static UnaryExpression |
dayOfWeek(Expression expression)
Returns a
UnaryExpression "$dayOfWeek" expression. |
static UnaryExpression |
dayOfYear(Expression expression)
Returns a
UnaryExpression "$dayOfYear" expression. |
static NaryExpression |
divide(Expression numerator,
Expression denominator)
Returns a
NaryExpression "$divide" expression. |
static NaryExpression |
eq(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$eq" expression. |
static Constant |
field(String fieldName)
Returns a
Constant expression with the provided
fieldName. |
static NaryExpression |
gt(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$gt" expression. |
static NaryExpression |
gte(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$gte"
expression. |
static UnaryExpression |
hour(Expression expression)
Returns a
UnaryExpression "$hour" expression. |
static NaryExpression |
ifNull(Expression first,
Expression second)
Returns a
NaryExpression "$ifNull" expression. |
static UnaryExpression |
let(Expression inExpression,
Element... variables)
Creates a
$let expression with the provided variables and
in expression. |
static UnaryExpression |
let(List<Element> variables,
Expression inExpression)
Creates a
$let expression with the provided variables and
in expression. |
static LetBuilder |
let(String name,
DocumentAssignable document)
Starts the creation of a
$let expression. |
static LetBuilder |
let(String name,
Expression expression)
Starts the creation of a
$let expression. |
static Constant |
literal(String value)
Returns a
Constant expression wrapping the value in a
"$literal" sub-document. |
static NaryExpression |
lt(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$lt" expression. |
static NaryExpression |
lte(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$lte" expression. |
static MapStage1 |
map(String inputField)
Returns a
UnaryExpression expression for the $map
operation. |
static UnaryExpression |
map(String inputField,
String variableName,
Expression mapOperation)
Returns a
UnaryExpression expression for the $map
operation. |
static UnaryExpression |
millisecond(Expression expression)
Returns a
UnaryExpression "$millisecond" expression. |
static UnaryExpression |
minute(Expression expression)
Returns a
UnaryExpression "$minute" expression. |
static NaryExpression |
mod(Expression numerator,
Expression denominator)
Returns a
NaryExpression "$mod" expression. |
static UnaryExpression |
month(Expression expression)
Returns a
UnaryExpression "$month" expression. |
static NaryExpression |
multiply(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$multiply" expression. |
static NaryExpression |
ne(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$ne" expression. |
static UnaryExpression |
not(Expression expression)
Returns a
UnaryExpression "$not" expression. |
static Constant |
nullConstant()
Returns a
null Constant expression. |
static NaryExpression |
or(Expression... expressions)
Returns an
NaryExpression "$or" expression. |
static UnaryExpression |
second(Expression expression)
Returns a
UnaryExpression "$second" expression. |
static Element |
set(String name,
DocumentAssignable document)
Returns an element to set the value to.
|
static Element |
set(String name,
Expression expression)
Returns an element to set the value to.
|
static NaryExpression |
setDifference(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$setDifference" expression. |
static NaryExpression |
setEquals(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$setEquals" expression. |
static NaryExpression |
setIntersection(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$setIntersection" expression. |
static NaryExpression |
setIsSubset(Expression subSet,
Expression completeSet)
Returns a
NaryExpression "$setIsSubset" expression. |
static NaryExpression |
setUnion(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$setUnion" expression. |
static UnaryExpression |
size(Expression expression)
Returns a
UnaryExpression "$size" expression. |
static NaryExpression |
strcasecmp(Expression lhs,
Expression rhs)
Returns a
NaryExpression
"$strcasecmp" expression. |
static NaryExpression |
substr(Expression string,
Expression skip,
Expression length)
Returns a
NaryExpression "$substr" expression. |
static NaryExpression |
subtract(Expression lhs,
Expression rhs)
Returns a
NaryExpression "$subtract" expression. |
static UnaryExpression |
toLower(Expression string)
Returns a
UnaryExpression "$toLower" expression. |
static UnaryExpression |
toUpper(Expression string)
Returns a
UnaryExpression "$toUpper" expression. |
static Constant |
var(String variableName)
Returns a
Constant expression with the provided
variableName. |
static UnaryExpression |
week(Expression expression)
Returns a
UnaryExpression "$week" expression. |
static UnaryExpression |
year(Expression expression)
Returns a
UnaryExpression "$year" expression. |
public static final String ADD
public static final String ALL_ELEMENTS_TRUE
public static final String AND
public static final String ANY_ELEMENT_TRUE
public static final String COMPARE
public static final String CONCATENATE
public static final String CONDITION
public static final String DAY_OF_MONTH
public static final String DAY_OF_WEEK
public static final String DAY_OF_YEAR
public static final String DIVIDE
public static final String EQUAL
public static final String GREATER_THAN
public static final String GREATER_THAN_OR_EQUAL
public static final String HOUR
public static final String IF_NULL
public static final String LESS_THAN
public static final String LESS_THAN_OR_EQUAL
public static final String LITERAL
public static final String MILLISECOND
public static final String MINUTE
public static final String MODULO
public static final String MONTH
public static final String MULTIPLY
public static final String NOT
public static final String NOT_EQUAL
public static final String OR
public static final String SECOND
public static final String SET_DIFFERENCE
public static final String SET_EQUALS
public static final String SET_INTERSECTION
public static final String SET_IS_SUBSET
public static final String SET_UNION
public static final String SIZE
public static final String STRING_CASE_INSENSITIVE_COMPARE
public static final String SUB_STRING
public static final String SUBTRACT
public static final String TO_LOWER
public static final String TO_UPPER
public static final String WEEK
public static final String YEAR
public static NaryExpression add(Expression... expressions)
NaryExpression
"$add" expression.expressions
- The sub-expressions.NaryExpression
"$add" expression.public static UnaryExpression allElementsTrue(Expression expression)
UnaryExpression
"$allElementsTrue" expression.expression
- The expression that will be evaluated to create the set to
inspect for a true element.UnaryExpression
"$allElementsTrue"
expression.public static NaryExpression and(Expression... expressions)
NaryExpression
"$and" expression.expressions
- The sub-expressions.NaryExpression
"$and" expression.public static UnaryExpression anyElementTrue(Expression expression)
UnaryExpression
"$anyElementTrue" expression.expression
- The expression that will be evaluated to create the set to
inspect for a true element.UnaryExpression
"$anyElementTrue"
expression.public static NaryExpression cmp(Expression lhs, Expression rhs)
NaryExpression
"$cmp" expression.lhs
- The left hand side of the operation.rhs
- The left hand side of the operation.NaryExpression
"$cmp" expression.public static NaryExpression concatenate(Expression... expression)
NaryExpression
"$concat" expression.expression
- The string expressions for the operator.NaryExpression
"$concat" expression.public static NaryExpression cond(Expression test, Expression trueResult, Expression falseResult)
NaryExpression
"$cond" expression.test
- The conditions test.trueResult
- The result if the test is true.falseResult
- The result if the test is false.NaryExpression
"$cond" expression.public static Constant constant(boolean value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(Date value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(double value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Expression constant(Element element)
Constant
expression wrapping the provided
element. This method is intended mainly for wrapping arrays
using the BuilderFactory.a()
method.import static
com.allanbank.mongodb.bson.builder.BuilderFactory.a
import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
constant( a( "This", "is", "an", "array" ) );
element
- The element value.Constant
expression.public static Constant constant(int value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(long value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(ObjectId value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(Pattern value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constant(String value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constantMongoTimestamp(long value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static Constant constantTimestamp(long value)
Constant
expression with the provided value.value
- The constants value.Constant
expression.public static UnaryExpression dayOfMonth(Expression expression)
UnaryExpression
"$dayOfMonth" expression.expression
- The date for the operator.UnaryExpression
"$dayOfMonth" expression.public static UnaryExpression dayOfWeek(Expression expression)
UnaryExpression
"$dayOfWeek" expression.expression
- The date for the operator.UnaryExpression
"$dayOfWeek" expression.public static UnaryExpression dayOfYear(Expression expression)
UnaryExpression
"$dayOfYear" expression.expression
- The date for the operator.UnaryExpression
"$dayOfYear" expression.public static NaryExpression divide(Expression numerator, Expression denominator)
NaryExpression
"$divide" expression.numerator
- The numerator of the division.denominator
- The denominator of the division.NaryExpression
"$divide" expression.public static NaryExpression eq(Expression lhs, Expression rhs)
NaryExpression
"$eq" expression.lhs
- The left hand side of the equals.rhs
- The right hand side of the equals.NaryExpression
"$eq" expression.public static Constant field(String fieldName)
Constant
expression with the provided
fieldName.
Prepends a $
to the field name if not already present.
Constant field = Expressions.field("field"); // Produces output: // $field System.out.println(field);
fieldName
- The name of the field.Constant
expression.public static NaryExpression gt(Expression lhs, Expression rhs)
NaryExpression
"$gt" expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$gt" expression.public static NaryExpression gte(Expression lhs, Expression rhs)
NaryExpression
"$gte"
expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$gte"
expression.public static UnaryExpression hour(Expression expression)
UnaryExpression
"$hour" expression.expression
- The date for the operator.UnaryExpression
"$hour" expression.public static NaryExpression ifNull(Expression first, Expression second)
NaryExpression
"$ifNull" expression.first
- The first expression.second
- The second expression.NaryExpression
"$ifNull" expression.public static UnaryExpression let(Expression inExpression, Element... variables)
$let
expression with the provided variables and
in
expression.
Here is the
let
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.cond
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; import staticcom.allanbank.mongodb.builder.expression.Expressions.field
; import staticcom.allanbank.mongodb.builder.expression.Expressions.let
; import staticcom.allanbank.mongodb.builder.expression.Expressions.multiply
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; Aggregate.Builder aggregate = Aggregate.builder(); // $project: { // finalTotal: { // $let: { // vars: { // total: { $add: [ '$price', '$tax' ] }, // discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } } // }, // in: { $multiply: [ "$$total", "$$discounted" ] } // } // } // } final Aggregate.Builder aggregation = Aggregate.builder(); aggregation.project( include(), set("finalTotal", let( multiply(var("total"), var("discounted")) set("total", add(field("price"), field("tax"))), set("discounted", cond(field("applyDiscount"), constant(0.9), constant(1)))))); // Aggregation Pipeline : '$pipeline' : [ // { // '$project' : { // finalTotal : { // '$let' : { // vars : { // total : { // '$add' : [ // '$price', // '$tax' // ] // }, // discounted : { // '$cond' : [ // '$applyDiscount', // 0.9, // 1 // ] // } // }, // in : { // '$multiply' : [ // '$$total', // '$$discounted' // ] // } // } // } // } // } // ] System.out.println("Aggregation Pipeline : " + aggregation);
inExpression
- The expression to be evaluated with the variables within the
$let
expression.variables
- The variables for the $let
expression.public static UnaryExpression let(List<Element> variables, Expression inExpression)
$let
expression with the provided variables and
in
expression.
Here is the
let
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.cond
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; import staticcom.allanbank.mongodb.builder.expression.Expressions.field
; import staticcom.allanbank.mongodb.builder.expression.Expressions.let
; import staticcom.allanbank.mongodb.builder.expression.Expressions.multiply
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; Aggregate.Builder aggregate = Aggregate.builder(); // $project: { // finalTotal: { // $let: { // vars: { // total: { $add: [ '$price', '$tax' ] }, // discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } } // }, // in: { $multiply: [ "$$total", "$$discounted" ] } // } // } // } final Aggregate.Builder aggregation = Aggregate.builder(); aggregation.project( include(), set("finalTotal", let( Arrays.asList( set("total", add(field("price"), field("tax"))), set("discounted", cond(field("applyDiscount"), constant(0.9), constant(1)))) multiply(var("total"), var("discounted"))))); // Aggregation Pipeline : '$pipeline' : [ // { // '$project' : { // finalTotal : { // '$let' : { // vars : { // total : { // '$add' : [ // '$price', // '$tax' // ] // }, // discounted : { // '$cond' : [ // '$applyDiscount', // 0.9, // 1 // ] // } // }, // in : { // '$multiply' : [ // '$$total', // '$$discounted' // ] // } // } // } // } // } // ] System.out.println("Aggregation Pipeline : " + aggregation);
variables
- The variables for the $let
expression.inExpression
- The expression to be evaluated with the variables within the
$let
expression.public static LetBuilder let(String name, DocumentAssignable document)
$let
expression. The returned
LetBuilder
can be used to add additional variables before setting
the final expression
to evaluate.
Here is the
let
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.cond
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; import staticcom.allanbank.mongodb.builder.expression.Expressions.field
; import staticcom.allanbank.mongodb.builder.expression.Expressions.let
; import staticcom.allanbank.mongodb.builder.expression.Expressions.multiply
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; Aggregate.Builder aggregate = Aggregate.builder(); // $project: { // finalTotal: { // $let: { // vars: { // total: { $add: [ '$price', '$tax' ] }, // discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } } // }, // in: { $multiply: [ "$$total", "$$discounted" ] } // } // } // } final Aggregate.Builder aggregation = Aggregate.builder(); aggregation.project( include(), set("finalTotal", let("total", add(field("price"), field("tax"))) .let("discounted", cond(field("applyDiscount"), constant(0.9), constant(1))) .in(multiply(var("total"), var("discounted"))))); // Aggregation Pipeline : '$pipeline' : [ // { // '$project' : { // finalTotal : { // '$let' : { // vars : { // total : { // '$add' : [ // '$price', // '$tax' // ] // }, // discounted : { // '$cond' : [ // '$applyDiscount', // 0.9, // 1 // ] // } // }, // in : { // '$multiply' : [ // '$$total', // '$$discounted' // ] // } // } // } // } // } // ] System.out.println("Aggregation Pipeline : " + aggregation);
name
- The name of the first field to set.document
- The document to set the first field value to.public static LetBuilder let(String name, Expression expression)
$let
expression. The returned
LetBuilder
can be used to add additional variables before setting
the final expression
to evaluate.
Here is the
let
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.cond
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; import staticcom.allanbank.mongodb.builder.expression.Expressions.field
; import staticcom.allanbank.mongodb.builder.expression.Expressions.let
; import staticcom.allanbank.mongodb.builder.expression.Expressions.multiply
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; Aggregate.Builder aggregate = Aggregate.builder(); // $project: { // finalTotal: { // $let: { // vars: { // total: { $add: [ '$price', '$tax' ] }, // discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } } // }, // in: { $multiply: [ "$$total", "$$discounted" ] } // } // } // } final Aggregate.Builder aggregation = Aggregate.builder(); aggregation.project( include(), set("finalTotal", let("total", add(field("price"), field("tax"))) .let("discounted", cond(field("applyDiscount"), constant(0.9), constant(1))) .in(multiply(var("total"), var("discounted"))))); // Aggregation Pipeline : '$pipeline' : [ // { // '$project' : { // finalTotal : { // '$let' : { // vars : { // total : { // '$add' : [ // '$price', // '$tax' // ] // }, // discounted : { // '$cond' : [ // '$applyDiscount', // 0.9, // 1 // ] // } // }, // in : { // '$multiply' : [ // '$$total', // '$$discounted' // ] // } // } // } // } // } // ] System.out.println("Aggregation Pipeline : " + aggregation);
name
- The name of the field to set.expression
- The expression to compute the value for the first field.public static Constant literal(String value)
Constant
expression wrapping the value in a
"$literal" sub-document.value
- The constants value.Constant
expression.public static NaryExpression lt(Expression lhs, Expression rhs)
NaryExpression
"$lt" expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$lt" expression.public static NaryExpression lte(Expression lhs, Expression rhs)
NaryExpression
"$lte" expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$lt" expression.public static MapStage1 map(String inputField)
UnaryExpression
expression for the $map
operation.
Prepends a $
to the inputField
name if not already
present.
Here is the
map
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.map
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; Aggregate.Builder aggregate = Aggregate.builder(); // { $project: { adjustments: { $map: { input: "$skews", // as: "adj", // in: { $add: [ "$$adj", 12 ] } } } } } aggregate.project( include(), set( "adjustments", map("skews").as("adj").in( add( var("adj"), constant(12) ) ) ) ); // Produces output: // { // '$project' : { // adjustments : { // '$map' { // input : '$skews', // as : 'adj', // in : { // '$add' : [ // '$$adj', // 12 // ] // } // } // } // } // } System.out.println(aggregate);
inputField
- The name of the input
field. The map operation
expression.$map
expression construction.map
expression documentationpublic static UnaryExpression map(String inputField, String variableName, Expression mapOperation)
UnaryExpression
expression for the $map
operation.
Prepends a $
to the inputField
name if not already
present.
Here is the
map
expression's documentation aggregation pipe line
using this helper class.
import static com.allanbank.mongodb.builder.AggregationProjectFields.include; import static
com.allanbank.mongodb.builder.expression.Expressions.map
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; import staticcom.allanbank.mongodb.builder.expression.Expressions.add
; import staticcom.allanbank.mongodb.builder.expression.Expressions.var
; import staticcom.allanbank.mongodb.builder.expression.Expressions.constant
; Aggregate.Builder aggregate = Aggregate.builder(); // { $project: { adjustments: { $map: { input: "$skews", // as: "adj", // in: { $add: [ "$$adj", 12 ] } } } } } aggregate.project( include(), set( "adjustments", map( "skews", "adj", add( var("adj"), constant(12) ) ) ) ); // Produces output: // { // '$project' : { // adjustments : { // '$map' { // input : '$skews', // as : 'adj', // in : { // '$add' : [ // '$$adj', // 12 // ] // } // } // } // } // } System.out.println(aggregate);
inputField
- The name of the input
field.variableName
- The name of the as
variable.mapOperation
- The map operation expression.UnaryExpression
expression.map
expression documentationpublic static UnaryExpression millisecond(Expression expression)
UnaryExpression
"$millisecond" expression.expression
- The date for the operator.UnaryExpression
"$millisecond" expression.public static UnaryExpression minute(Expression expression)
UnaryExpression
"$minute" expression.expression
- The date for the operator.UnaryExpression
"$minute" expression.public static NaryExpression mod(Expression numerator, Expression denominator)
NaryExpression
"$mod" expression.numerator
- The numerator of the modulo operation.denominator
- The denominator of the modulo operation.NaryExpression
"$mod" expression.public static UnaryExpression month(Expression expression)
UnaryExpression
"$month" expression.expression
- The date for the operator.UnaryExpression
"$month" expression.public static NaryExpression multiply(Expression lhs, Expression rhs)
NaryExpression
"$multiply" expression.lhs
- The left hand side of the operator.rhs
- The right hand side of the operator.NaryExpression
"$multiply" expression.public static NaryExpression ne(Expression lhs, Expression rhs)
NaryExpression
"$ne" expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$ne" expression.public static UnaryExpression not(Expression expression)
UnaryExpression
"$not" expression.expression
- The sub expressions for the $not.UnaryExpression
"$not" expression.public static Constant nullConstant()
null
Constant
expression.Constant
expression.public static NaryExpression or(Expression... expressions)
NaryExpression
"$or" expression.expressions
- The sub-expressions.NaryExpression
"$or" expression.public static UnaryExpression second(Expression expression)
UnaryExpression
"$second" expression.expression
- The date for the operator.UnaryExpression
"$second" expression.public static Element set(String name, DocumentAssignable document)
name
- The name of the field to set.document
- The document to set the document to.public static Element set(String name, Expression expression)
name
- The name of the field to set.expression
- The expression to compute the value for the field.public static NaryExpression setDifference(Expression lhs, Expression rhs)
NaryExpression
"$setDifference" expression.lhs
- The expression that will be evaluated to create the first set.rhs
- The expression that will be evaluated to create the second
set.NaryExpression
"$setDifference" expression.public static NaryExpression setEquals(Expression lhs, Expression rhs)
NaryExpression
"$setEquals" expression.lhs
- The expression that will be evaluated to create the first set.rhs
- The expression that will be evaluated to create the second
set.NaryExpression
"$setEquals" expression.public static NaryExpression setIntersection(Expression lhs, Expression rhs)
NaryExpression
"$setIntersection" expression.lhs
- The expression that will be evaluated to create the first set.rhs
- The expression that will be evaluated to create the second
set.NaryExpression
"$setIntersection" expression.public static NaryExpression setIsSubset(Expression subSet, Expression completeSet)
NaryExpression
"$setIsSubset" expression.subSet
- The expression that will be tested to see if it is a subset of
the completeSet
.completeSet
- The expression that will be evaluated to construct the
complete set of values.NaryExpression
"$setIsSubset" expression.public static NaryExpression setUnion(Expression lhs, Expression rhs)
NaryExpression
"$setUnion" expression.lhs
- The expression that will be evaluated to create the first set.rhs
- The expression that will be evaluated to create the second
set.NaryExpression
"$setUnion" expression.public static UnaryExpression size(Expression expression)
UnaryExpression
"$size" expression.expression
- The expression that will be evaluated to create the set to
inspect for a true element.UnaryExpression
"$size" expression.public static NaryExpression strcasecmp(Expression lhs, Expression rhs)
NaryExpression
"$strcasecmp" expression.lhs
- The left hand side of the comparison.rhs
- The right hand side of the comparison.NaryExpression
"$strcasecmp" expression.public static NaryExpression substr(Expression string, Expression skip, Expression length)
NaryExpression
"$substr" expression.string
- The string to pull a sub-string from.skip
- The number of characters to skip in the string.length
- The length of the string to extract.NaryExpression
"$substr" expression.public static NaryExpression subtract(Expression lhs, Expression rhs)
NaryExpression
"$subtract" expression.lhs
- The left hand side of the operator.rhs
- The right hand side of the operator.NaryExpression
"$subtract" expression.public static UnaryExpression toLower(Expression string)
UnaryExpression
"$toLower" expression.string
- The string to modify.UnaryExpression
"$toLower" expression.public static UnaryExpression toUpper(Expression string)
UnaryExpression
"$toUpper" expression.string
- The string to modify.UnaryExpression
"$toUpper" expression.public static Constant var(String variableName)
Constant
expression with the provided
variableName. See the $let
and $map
expressions for example usage.
Prepends a $$
to the variable name if not already present.
Constant variable = Expressions.var("variable"); // Produces output: // $$variable System.out.println(variable);
variableName
- The name of the field.Constant
expression.public static UnaryExpression week(Expression expression)
UnaryExpression
"$week" expression.expression
- The date for the operator.UnaryExpression
"$week" expression.public static UnaryExpression year(Expression expression)
UnaryExpression
"$year" expression.expression
- The date for the operator.UnaryExpression
"$year" expression.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.