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
ProjectionOperation
s on a field.- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ProjectionOperationBuilder
(Object value, ProjectionOperation operation, org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection previousProjection) Creates a newProjectionOperation.ProjectionOperationBuilder
for 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.ProjectionOperationBuilder
for the field with the given name on top of the givenProjectionOperation
. -
Method Summary
Modifier and TypeMethodDescriptionGenerates a$abs
expression that takes the number of the previously mentioned field and returns the absolute value of it.Generates an$allElementsTrue
expression that takes array of the previously mentioned field and returns true if no elements is false.Generates an$anyElementTrue
expression 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$arrayElemAt
expression 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$literal
expression that Takes the value previously and uses it as literal.ceil()
Generates a$ceil
expression that takes the number of the previously mentioned field and returns the smallest integer greater than or equal to the specified number.Generates a$cmp
expression (compare to) that compares the value of the field to a given value or field.Generates a$concat
expression that takes the string representation of the previously mentioned field and concats given values to it.concatArrays
(String... fields) Generates a$concatArrays
expression that takes the string representation of the previously mentioned field and concats it with the arrays from the referenced fields.Generates a$dateToString
expression that takes the date representation of the previously mentioned field using the server default format.dateAsFormattedString
(String format) Generates a$dateToString
expression that takes the date representation of the previously mentioned field and applies given format to it.differenceToArray
(String array) Generates a$setDifference
expression 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$divide
expression that divides the previously mentioned field by the given number.Generates an$divide
expression that divides the value of the given field by the previously mentioned field.divide
(AggregationExpression expression) Generates an$divide
expression that divides the value of the previously mentioned by the result of theAggregationExpression
.Generates a$eq
expression (equal) that compares the value of the field to a given value or field.equalsArrays
(String... arrays) Generates a$setEquals
expression 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$exp
expression 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$filter
expression that returns a subset of the array held by the given field.floor()
Generates a$floor
expression that takes the number of the previously mentioned field and returns the largest integer less than or equal to it.Generates a$gt
expression (greater than) that compares the value of the field to a given value or field.Generates a$gte
expression (greater than equal) that compares the value of the field to a given value or field.intersectsArrays
(String... arrays) Generates a$setIntersection
expression 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$isArray
expression 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$let
expression 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$let
expression that binds variables for use in the specified expression, and returns the result of the expression.ln()
Generates a$ln
expression that takes the number of the previously mentioned field and calculates the natural logarithm ln (i.e loge) of it.Generates a$log
expression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.Generates a$log
expression 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$log
expression that takes the number of the previously mentioned field and calculates the log of the associated number in the specified base.log10()
Generates a$log10
expression that takes the number of the previously mentioned field and calculates the log base 10.Generates a$lt
expression (less than) that compares the value of the field to a given value or field.Generates a$lte
expression (less than equal) that compares the value of the field to a given value or field.Generates an$subtract
expression that subtracts the given number to the previously mentioned field.Generates an$subtract
expression that subtracts the value of the given field to the previously mentioned field.minus
(AggregationExpression expression) Generates an$subtract
expression that subtracts the result of the givenAggregationExpression
from the previously mentioned field.Generates an$mod
expression that divides the previously mentioned field by the given number and returns the remainder.Generates an$mod
expression that divides the value of the given field by the previously mentioned field and returns the remainder.mod
(AggregationExpression expression) Generates an$mod
expression that divides the value of the previously mentioned field by the result of theAggregationExpression
.Generates an$multiply
expression that multiplies the given number with the previously mentioned field.Generates an$multiply
expression that multiplies the value of the given field with the previously mentioned field.multiply
(AggregationExpression expression) Generates an$multiply
expression that multiplies the previously with the result of theAggregationExpression
. mentioned field.Generates a$ne
expression (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$add
expression that adds the given number to the previously mentioned field.Generates an$add
expression that adds the value of the given field to the previously mentioned field.Generates a$pow
expression that takes the number of the previously mentioned field and raises it by the specified exponent.Generates a$pow
expression that takes the number of the previously mentioned field and raises it by the specified exponent.pow
(AggregationExpression exponentExpression) Generates a$pow
expression 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$size
expression that returns the size of the array held by the given field.slice
(int count) Generates a$slice
expression that returns a subset of the array held by the given field.slice
(int count, int offset) Generates a$slice
expression that returns a subset of the array held by the given field.sqrt()
Generates a$sqrt
expression that takes the number of the previously mentioned field and calculates the square root.strCaseCmp
(String value) Generates a$strcasecmp
expression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the given value.strCaseCmp
(AggregationExpression expression) Generates a$strcasecmp
expression 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$strcasecmp
expression that takes the string representation of the previously mentioned field and performs case-insensitive comparison to the referenced fieldRef.subsetOfArray
(String array) Generates a$setIsSubset
expression 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$substr
expression 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$substr
expression 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.Document
toDocument
(AggregationOperationContext context) toLower()
Generates a$toLower
expression that takes the string representation of the previously mentioned field and lowers it.toUpper()
Generates a$toUpper
expression 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$setUnion
expression 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, wait
Methods 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.ProjectionOperationBuilder
for 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.ProjectionOperationBuilder
for 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_id
as 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$add
expression that adds the given number to the previously mentioned field.- Parameters:
number
-- Returns:
-
plus
Generates an$add
expression that adds the value of the given field to the previously mentioned field.- Parameters:
fieldReference
-- Returns:
-
minus
Generates an$subtract
expression that subtracts the given number to the previously mentioned field.- Parameters:
number
-- Returns:
-
minus
Generates an$subtract
expression that subtracts the value of the given field to the previously mentioned field.- Parameters:
fieldReference
-- Returns:
-
minus
Generates an$subtract
expression that subtracts the result of the givenAggregationExpression
from the previously mentioned field.- Parameters:
expression
- must not be null.- Returns:
- Since:
- 1.10
-
multiply
Generates an$multiply
expression that multiplies the given number with the previously mentioned field.- Parameters:
number
-- Returns:
-
multiply
Generates an$multiply
expression that multiplies the value of the given field with the previously mentioned field.- Parameters:
fieldReference
-- Returns:
-
multiply
Generates an$multiply
expression that multiplies the previously with the result of theAggregationExpression
. mentioned field.- Parameters:
expression
- must not be null.- Returns:
- Since:
- 1.10
-
divide
Generates an$divide
expression that divides the previously mentioned field by the given number.- Parameters:
number
-- Returns:
-
divide
Generates an$divide
expression that divides the value of the given field by the previously mentioned field.- Parameters:
fieldReference
-- Returns:
-
divide
Generates an$divide
expression 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$mod
expression that divides the previously mentioned field by the given number and returns the remainder.- Parameters:
number
-- Returns:
-
mod
Generates an$mod
expression that divides the value of the given field by the previously mentioned field and returns the remainder.- Parameters:
fieldReference
-- Returns:
-
mod
Generates an$mod
expression 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$size
expression that returns the size of the array held by the given field.- Returns:
- never null.
- Since:
- 1.7
-
cmp
Generates a$cmp
expression (compare to) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
eq
Generates a$eq
expression (equal) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
gt
Generates a$gt
expression (greater than) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
gte
Generates a$gte
expression (greater than equal) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
lt
Generates a$lt
expression (less than) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
lte
Generates a$lte
expression (less than equal) that compares the value of the field to a given value or field.- Parameters:
compareValue
- the compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
ne
Generates a$ne
expression (not equal) that compares the value of the field to a given value or field.- Parameters:
compareValue
- compare value or aField
object.- Returns:
- never null.
- Since:
- 1.10
-
slice
Generates a$slice
expression 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$slice
expression 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$filter
expression 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
- TheAggregationExpression
that determines whether to include the element in the resulting array. Must not be null.- Returns:
- never null.
- Since:
- 1.10
-
equalsArrays
Generates a$setEquals
expression 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$setIntersection
expression 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$setUnion
expression 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$setDifference
expression 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$setIsSubset
expression 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$anyElementTrue
expression 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$allElementsTrue
expression 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$abs
expression 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$ceil
expression 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$exp
expression 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$floor
expression 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$ln
expression 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$log
expression 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$log
expression 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$log
expression 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$log10
expression that takes the number of the previously mentioned field and calculates the log base 10.- Returns:
- never null.
- Since:
- 1.10
-
pow
Generates a$pow
expression 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$pow
expression 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$pow
expression 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$sqrt
expression 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$concat
expression 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$substr
expression 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$substr
expression 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$toLower
expression that takes the string representation of the previously mentioned field and lowers it.- Returns:
- Since:
- 1.10
-
toUpper
Generates a$toUpper
expression that takes the string representation of the previously mentioned field and uppers it.- Returns:
- Since:
- 1.10
-
strCaseCmp
Generates a$strcasecmp
expression 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$strcasecmp
expression 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$strcasecmp
expression 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$arrayElemAt
expression 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$concatArrays
expression 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$isArray
expression that takes the string representation of the previously mentioned field and checks if its an array.- Returns:
- Since:
- 1.10
-
asLiteral
Generates a$literal
expression that Takes the value previously and uses it as literal.- Returns:
- Since:
- 1.10
-
dateAsFormattedString
Generates a$dateToString
expression 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$dateToString
expression 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$let
expression that binds variables for use in the specified expression, and returns the result of the expression.- Parameters:
valueExpression
- TheAggregationExpression
bound to variableName.variableName
- The variable name to be used in the inAggregationExpression
.in
- TheAggregationExpression
to evaluate.- Returns:
- never null.
- Since:
- 1.10
-
let
public ProjectionOperation.ProjectionOperationBuilder let(Collection<VariableOperators.Let.ExpressionVariable> variables, AggregationExpression in) Generates a$let
expression that binds variables for use in the specified expression, and returns the result of the expression.- Parameters:
variables
- The boundVariableOperators.Let.ExpressionVariable
s.in
- TheAggregationExpression
to evaluate.- Returns:
- never null.
- Since:
- 1.10
-
toDocument
Description copied from interface:AggregationOperation
- Specified by:
toDocument
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to 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:
-