Module spring.data.mongodb
Class ProjectionOperation.ProjectionOperationBuilder
java.lang.Object
org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder
- All Implemented Interfaces:
AggregationOperation
- Direct Known Subclasses:
ProjectionOperation.ExpressionProjectionOperationBuilder
- Enclosing class:
- ProjectionOperation
Builder for
ProjectionOperations on a field.- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProjectionOperationBuilder(Object value, ProjectionOperation operation, org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection previousProjection) Creates a newProjectionOperation.ProjectionOperationBuilderfor the field with the given value on top of the givenProjectionOperation.ProjectionOperationBuilder(String name, ProjectionOperation operation, org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection previousProjection) Creates a newProjectionOperation.ProjectionOperationBuilderfor the field with the given name on top of the givenProjectionOperation. -
Method Summary
Modifier and TypeMethodDescriptionGenerates a$absexpression that takes the number of the previously mentioned field and returns the absolute value of it.Generates an$allElementsTrueexpression that takes array of the previously mentioned field and returns true if no elements is false.Generates an$anyElementTrueexpression that Takes array of the previously mentioned field and returns true if any of the elements are true and false otherwise.Apply a conditional projection usingConditionalOperators.Cond.Apply a conditional value replacement for null values usingConditionalOperators.IfNull.arrayElementAt(int position) Generates a$arrayElemAtexpression that takes the string representation of the previously mentioned field and returns the element at the specified array position.Allows to specify an alias for the previous projection operation.Generates a$literalexpression that Takes the value previously and uses it as literal.ceil()Generates a$ceilexpression that takes the number of the previously mentioned field and returns the smallest integer greater than or equal to the specified number.Generates a$cmpexpression (compare to) that compares the value of the field to a given value or field.Generates a$concatexpression that takes the string representation of the previously mentioned field and concats given values to it.concatArrays(String... fields) Generates a$concatArraysexpression that takes the string representation of the previously mentioned field and concats it with the arrays from the referenced fields.Generates a$dateToStringexpression that takes the date representation of the previously mentioned field using the server default format.dateAsFormattedString(String format) Generates a$dateToStringexpression that takes the date representation of the previously mentioned field and applies given format to it.differenceToArray(String array) Generates a$setDifferenceexpression that takes array of the previously mentioned field and returns an array containing the elements that do not exist in the given array.Generates an$divideexpression that divides the previously mentioned field by the given number.Generates an$divideexpression that divides the value of the given field by the previously mentioned field.divide(AggregationExpression expression) Generates an$divideexpression that divides the value of the previously mentioned by the result of theAggregationExpression.Generates a$eqexpression (equal) that compares the value of the field to a given value or field.equalsArrays(String... arrays) Generates a$setEqualsexpression that compares the previously mentioned field to one or more arrays and returns true if they have the same distinct elements and false otherwise.exp()Generates a$expexpression that takes the number of the previously mentioned field and raises Euler’s number (i.e. e ) on it.Extracts the dayOfMonth from a date expression.Extracts the dayOfWeek from a date expression.Extracts the dayOfYear from a date expression.Extracts the hour from a date expression.Extracts the millisecond from a date expression.Extracts the minute from a date expression.Extracts the month from a date expression.Extracts the second from a date expression.Extracts the week from a date expression.Extracts the year from a date expression.filter(String as, AggregationExpression condition) Generates a$filterexpression that returns a subset of the array held by the given field.floor()Generates a$floorexpression that takes the number of the previously mentioned field and returns the largest integer less than or equal to it.Generates a$gtexpression (greater than) that compares the value of the field to a given value or field.Generates a$gteexpression (greater than equal) that compares the value of the field to a given value or field.intersectsArrays(String... arrays) Generates a$setIntersectionexpression that takes array of the previously mentioned field and one or more arrays and returns an array that contains the elements that appear in every of those.isArray()Generates a$isArrayexpression that takes the string representation of the previously mentioned field and checks if its an array.let(Collection<VariableOperators.Let.ExpressionVariable> variables, AggregationExpression in) Generates a$letexpression that binds variables for use in the specified expression, and returns the result of the expression.let(AggregationExpression valueExpression, String variableName, AggregationExpression in) Generates a$letexpression that binds variables for use in the specified expression, and returns the result of the expression.ln()Generates a$lnexpression that takes the number of the previously mentioned field and calculates the natural logarithm ln (i.e loge) of it.Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.log(AggregationExpression base) Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.log10()Generates a$log10expression that takes the number of the previously mentioned field and calculates the log base 10.Generates a$ltexpression (less than) that compares the value of the field to a given value or field.Generates a$lteexpression (less than equal) that compares the value of the field to a given value or field.Generates an$subtractexpression that subtracts the given number to the previously mentioned field.Generates an$subtractexpression that subtracts the value of the given field to the previously mentioned field.minus(AggregationExpression expression) Generates an$subtractexpression that subtracts the result of the givenAggregationExpressionfrom the previously mentioned field.Generates an$modexpression that divides the previously mentioned field by the given number and returns the remainder.Generates an$modexpression that divides the value of the given field by the previously mentioned field and returns the remainder.mod(AggregationExpression expression) Generates an$modexpression that divides the value of the previously mentioned field by the result of theAggregationExpression.Generates an$multiplyexpression that multiplies the given number with the previously mentioned field.Generates an$multiplyexpression that multiplies the value of the given field with the previously mentioned field.multiply(AggregationExpression expression) Generates an$multiplyexpression that multiplies the previously with the result of theAggregationExpression. mentioned field.Generates a$neexpression (not equal) that compares the value of the field to a given value or field.Defines a nested field binding for the current field.Generates an$addexpression that adds the given number to the previously mentioned field.Generates an$addexpression that adds the value of the given field to the previously mentioned field.Generates a$powexpression that takes the number of the previously mentioned field and raises it by the specified exponent.Generates a$powexpression that takes the number of the previously mentioned field and raises it by the specified exponent.pow(AggregationExpression exponentExpression) Generates a$powexpression that Takes the number of the previously mentioned field and raises it by the specified exponent.Projects the result of the previous operation onto the current field.Adds a generic projection for the current field.size()Generates a$sizeexpression that returns the size of the array held by the given field.slice(int count) Generates a$sliceexpression that returns a subset of the array held by the given field.slice(int count, int offset) Generates a$sliceexpression that returns a subset of the array held by the given field.sqrt()Generates a$sqrtexpression that takes the number of the previously mentioned field and calculates the square root.strCaseCmp(String value) Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the given value.strCaseCmp(AggregationExpression expression) Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the result of the givenAggregationExpression.strCaseCmpValueOf(String fieldRef) Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the referenced fieldRef.subsetOfArray(String array) Generates a$setIsSubsetexpression that takes array of the previously mentioned field and returns true if it is a subset of the given array.substring(int start) Generates a$substrexpression that Takes the string representation of the previously mentioned field and returns a substring starting at a specified index position.substring(int start, int nrOfChars) Generates a$substrexpression that takes the string representation of the previously mentioned field and returns a substring starting at a specified index position including the specified number of characters.org.bson.DocumenttoDocument(AggregationOperationContext context) toLower()Generates a$toLowerexpression that takes the string representation of the previously mentioned field and lowers it.toUpper()Generates a$toUpperexpression that takes the string representation of the previously mentioned field and uppers it.trunc()Takes the number of the previously mentioned field and truncates it to its integer value.unionArrays(String... arrays) Generates a$setUnionexpression that takes array of the previously mentioned field and one or more arrays and returns an array that contains the elements that appear in any of those.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationOperation
getOperator, toPipelineStages
-
Field Details
-
value
-
operation
-
-
Constructor Details
-
ProjectionOperationBuilder
public ProjectionOperationBuilder(String name, ProjectionOperation operation, @Nullable org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection previousProjection) Creates a newProjectionOperation.ProjectionOperationBuilderfor the field with the given name on top of the givenProjectionOperation.- Parameters:
name- must not be null or empty.operation- must not be null.previousProjection- the previous operation projection, may be null.
-
ProjectionOperationBuilder
protected ProjectionOperationBuilder(Object value, ProjectionOperation operation, @Nullable org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection previousProjection) Creates a newProjectionOperation.ProjectionOperationBuilderfor the field with the given value on top of the givenProjectionOperation.- Parameters:
value-operation-previousProjection-
-
-
Method Details
-
previousOperation
Projects the result of the previous operation onto the current field. Will automatically add an exclusion for_idas what would be held in it by default will now go into the field just projected into.- Returns:
-
nested
Defines a nested field binding for the current field.- Parameters:
fields- must not be null.- Returns:
-
as
Allows to specify an alias for the previous projection operation.- Parameters:
alias-- Returns:
-
applyCondition
Apply a conditional projection usingConditionalOperators.Cond.- Parameters:
cond- must not be null.- Returns:
- never null.
-
applyCondition
Apply a conditional value replacement for null values usingConditionalOperators.IfNull.- Parameters:
ifNull- must not be null.- Returns:
- never null.
-
plus
Generates an$addexpression that adds the given number to the previously mentioned field.- Parameters:
number-- Returns:
-
plus
Generates an$addexpression that adds the value of the given field to the previously mentioned field.- Parameters:
fieldReference-- Returns:
-
minus
Generates an$subtractexpression that subtracts the given number to the previously mentioned field.- Parameters:
number-- Returns:
-
minus
Generates an$subtractexpression that subtracts the value of the given field to the previously mentioned field.- Parameters:
fieldReference-- Returns:
-
minus
Generates an$subtractexpression that subtracts the result of the givenAggregationExpressionfrom the previously mentioned field.- Parameters:
expression- must not be null.- Returns:
- Since:
- 1.10
-
multiply
Generates an$multiplyexpression that multiplies the given number with the previously mentioned field.- Parameters:
number-- Returns:
-
multiply
Generates an$multiplyexpression that multiplies the value of the given field with the previously mentioned field.- Parameters:
fieldReference-- Returns:
-
multiply
Generates an$multiplyexpression that multiplies the previously with the result of theAggregationExpression. mentioned field.- Parameters:
expression- must not be null.- Returns:
- Since:
- 1.10
-
divide
Generates an$divideexpression that divides the previously mentioned field by the given number.- Parameters:
number-- Returns:
-
divide
Generates an$divideexpression that divides the value of the given field by the previously mentioned field.- Parameters:
fieldReference-- Returns:
-
divide
Generates an$divideexpression that divides the value of the previously mentioned by the result of theAggregationExpression.- Parameters:
expression- must not be null.- Returns:
- Since:
- 1.10
-
mod
Generates an$modexpression that divides the previously mentioned field by the given number and returns the remainder.- Parameters:
number-- Returns:
-
mod
Generates an$modexpression that divides the value of the given field by the previously mentioned field and returns the remainder.- Parameters:
fieldReference-- Returns:
-
mod
Generates an$modexpression that divides the value of the previously mentioned field by the result of theAggregationExpression.- Parameters:
expression- must not be null.- Returns:
- Since:
- 1.10
-
size
Generates a$sizeexpression that returns the size of the array held by the given field.- Returns:
- never null.
- Since:
- 1.7
-
cmp
Generates a$cmpexpression (compare to) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
eq
Generates a$eqexpression (equal) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
gt
Generates a$gtexpression (greater than) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
gte
Generates a$gteexpression (greater than equal) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
lt
Generates a$ltexpression (less than) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
lte
Generates a$lteexpression (less than equal) that compares the value of the field to a given value or field.- Parameters:
compareValue- the compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
ne
Generates a$neexpression (not equal) that compares the value of the field to a given value or field.- Parameters:
compareValue- compare value or aFieldobject.- Returns:
- never null.
- Since:
- 1.10
-
slice
Generates a$sliceexpression that returns a subset of the array held by the given field.
If n is positive, $slice returns up to the first n elements in the array.
If n is negative, $slice returns up to the last n elements in the array.- Parameters:
count- max number of elements.- Returns:
- never null.
- Since:
- 1.10
-
slice
Generates a$sliceexpression that returns a subset of the array held by the given field.- Parameters:
count- max number of elements. Must not be negative.offset- the offset within the array to start from.- Returns:
- never null.
- Since:
- 1.10
-
filter
public ProjectionOperation.ProjectionOperationBuilder filter(String as, AggregationExpression condition) Generates a$filterexpression that returns a subset of the array held by the given field.- Parameters:
as- The variable name for the element in the input array. Must not be null.condition- TheAggregationExpressionthat determines whether to include the element in the resulting array. Must not be null.- Returns:
- never null.
- Since:
- 1.10
-
equalsArrays
Generates a$setEqualsexpression that compares the previously mentioned field to one or more arrays and returns true if they have the same distinct elements and false otherwise.- Parameters:
arrays- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
intersectsArrays
Generates a$setIntersectionexpression that takes array of the previously mentioned field and one or more arrays and returns an array that contains the elements that appear in every of those.- Parameters:
arrays- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
unionArrays
Generates a$setUnionexpression that takes array of the previously mentioned field and one or more arrays and returns an array that contains the elements that appear in any of those.- Parameters:
arrays- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
differenceToArray
Generates a$setDifferenceexpression that takes array of the previously mentioned field and returns an array containing the elements that do not exist in the given array.- Parameters:
array- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
subsetOfArray
Generates a$setIsSubsetexpression that takes array of the previously mentioned field and returns true if it is a subset of the given array.- Parameters:
array- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
anyElementInArrayTrue
Generates an$anyElementTrueexpression that Takes array of the previously mentioned field and returns true if any of the elements are true and false otherwise.- Returns:
- never null.
- Since:
- 1.10
-
allElementsInArrayTrue
Generates an$allElementsTrueexpression that takes array of the previously mentioned field and returns true if no elements is false.- Returns:
- never null.
- Since:
- 1.10
-
absoluteValue
Generates a$absexpression that takes the number of the previously mentioned field and returns the absolute value of it.- Returns:
- never null.
- Since:
- 1.10
-
ceil
Generates a$ceilexpression that takes the number of the previously mentioned field and returns the smallest integer greater than or equal to the specified number.- Returns:
- never null.
- Since:
- 1.10
-
exp
Generates a$expexpression that takes the number of the previously mentioned field and raises Euler’s number (i.e. e ) on it.- Returns:
- never null.
- Since:
- 1.10
-
floor
Generates a$floorexpression that takes the number of the previously mentioned field and returns the largest integer less than or equal to it.- Returns:
- never null.
- Since:
- 1.10
-
ln
Generates a$lnexpression that takes the number of the previously mentioned field and calculates the natural logarithm ln (i.e loge) of it.- Returns:
- never null.
- Since:
- 1.10
-
log
Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.- Parameters:
baseFieldRef- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
log
Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.- Parameters:
base- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
log
Generates a$logexpression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.- Parameters:
base- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
log10
Generates a$log10expression that takes the number of the previously mentioned field and calculates the log base 10.- Returns:
- never null.
- Since:
- 1.10
-
pow
Generates a$powexpression that takes the number of the previously mentioned field and raises it by the specified exponent.- Parameters:
exponentFieldRef- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
pow
Generates a$powexpression that takes the number of the previously mentioned field and raises it by the specified exponent.- Parameters:
exponent- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
pow
Generates a$powexpression that Takes the number of the previously mentioned field and raises it by the specified exponent.- Parameters:
exponentExpression- must not be null.- Returns:
- never null.
- Since:
- 1.10
-
sqrt
Generates a$sqrtexpression that takes the number of the previously mentioned field and calculates the square root.- Returns:
- never null.
- Since:
- 1.10
-
trunc
Takes the number of the previously mentioned field and truncates it to its integer value.- Returns:
- never null.
- Since:
- 1.10
-
concat
Generates a$concatexpression that takes the string representation of the previously mentioned field and concats given values to it.- Returns:
- never null.
- Since:
- 1.10
-
substring
Generates a$substrexpression that Takes the string representation of the previously mentioned field and returns a substring starting at a specified index position.- Parameters:
start-- Returns:
- Since:
- 1.10
-
substring
Generates a$substrexpression that takes the string representation of the previously mentioned field and returns a substring starting at a specified index position including the specified number of characters.- Parameters:
start-nrOfChars-- Returns:
- Since:
- 1.10
-
toLower
Generates a$toLowerexpression that takes the string representation of the previously mentioned field and lowers it.- Returns:
- Since:
- 1.10
-
toUpper
Generates a$toUpperexpression that takes the string representation of the previously mentioned field and uppers it.- Returns:
- Since:
- 1.10
-
strCaseCmp
Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the given value.- Parameters:
value- must not be null.- Returns:
- Since:
- 1.10
-
strCaseCmpValueOf
Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the referenced fieldRef.- Parameters:
fieldRef- must not be null.- Returns:
- Since:
- 1.10
-
strCaseCmp
Generates a$strcasecmpexpression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the result of the givenAggregationExpression.- Parameters:
expression- must not be null.- Returns:
- Since:
- 1.10
-
arrayElementAt
Generates a$arrayElemAtexpression that takes the string representation of the previously mentioned field and returns the element at the specified array position.- Parameters:
position-- Returns:
- Since:
- 1.10
-
concatArrays
Generates a$concatArraysexpression that takes the string representation of the previously mentioned field and concats it with the arrays from the referenced fields.- Parameters:
fields- must not be null.- Returns:
- Since:
- 1.10
-
isArray
Generates a$isArrayexpression that takes the string representation of the previously mentioned field and checks if its an array.- Returns:
- Since:
- 1.10
-
asLiteral
Generates a$literalexpression that Takes the value previously and uses it as literal.- Returns:
- Since:
- 1.10
-
dateAsFormattedString
Generates a$dateToStringexpression that takes the date representation of the previously mentioned field and applies given format to it.- Parameters:
format- must not be null.- Returns:
- Since:
- 1.10
-
dateAsFormattedString
Generates a$dateToStringexpression that takes the date representation of the previously mentioned field using the server default format.
NOTE: Requires MongoDB 4.0 or later.- Returns:
- Since:
- 2.1
-
let
public ProjectionOperation.ProjectionOperationBuilder let(AggregationExpression valueExpression, String variableName, AggregationExpression in) Generates a$letexpression that binds variables for use in the specified expression, and returns the result of the expression.- Parameters:
valueExpression- TheAggregationExpressionbound to variableName.variableName- The variable name to be used in the inAggregationExpression.in- TheAggregationExpressionto evaluate.- Returns:
- never null.
- Since:
- 1.10
-
let
public ProjectionOperation.ProjectionOperationBuilder let(Collection<VariableOperators.Let.ExpressionVariable> variables, AggregationExpression in) Generates a$letexpression that binds variables for use in the specified expression, and returns the result of the expression.- Parameters:
variables- The boundVariableOperators.Let.ExpressionVariables.in- TheAggregationExpressionto evaluate.- Returns:
- never null.
- Since:
- 1.10
-
toDocument
Description copied from interface:AggregationOperation- Specified by:
toDocumentin interfaceAggregationOperation- Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the Document
-
project
Adds a generic projection for the current field.- Parameters:
operation- the operation key, e.g.$add.values- the values to be set for the projection operation.- Returns:
-
extractMinute
Extracts the minute from a date expression.- Returns:
-
extractHour
Extracts the hour from a date expression.- Returns:
-
extractSecond
Extracts the second from a date expression.- Returns:
-
extractMillisecond
Extracts the millisecond from a date expression.- Returns:
-
extractYear
Extracts the year from a date expression.- Returns:
-
extractMonth
Extracts the month from a date expression.- Returns:
-
extractWeek
Extracts the week from a date expression.- Returns:
-
extractDayOfYear
Extracts the dayOfYear from a date expression.- Returns:
-
extractDayOfMonth
Extracts the dayOfMonth from a date expression.- Returns:
-
extractDayOfWeek
Extracts the dayOfWeek from a date expression.- Returns:
-