Class ArrayExpressions
- java.lang.Object
-
- dev.morphia.aggregation.expressions.ArrayExpressions
-
public final class ArrayExpressions extends Object
Defines helper methods for the array expressions- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static dev.morphia.aggregation.expressions.impls.ArrayExpression
array(dev.morphia.aggregation.expressions.impls.Expression... expressions)
Creates an array of the given expressions.static dev.morphia.aggregation.expressions.impls.ArrayExpression
array(Object... objects)
Creates an array of the given objects.static dev.morphia.aggregation.expressions.impls.Expression
arrayToObject(dev.morphia.aggregation.expressions.impls.Expression array)
Converts an array of key value pairs to a document.static dev.morphia.aggregation.expressions.impls.Expression
concatArrays(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression additional)
Concatenates arrays to return the concatenated array.static dev.morphia.aggregation.expressions.impls.Expression
elementAt(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression index)
Returns the element at the specified array index.static dev.morphia.aggregation.expressions.impls.ArrayFilterExpression
filter(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression conditional)
Selects a subset of the array to return an array with only the elements that match the filter condition.static dev.morphia.aggregation.expressions.impls.Expression
in(dev.morphia.aggregation.expressions.impls.Expression search, dev.morphia.aggregation.expressions.impls.Expression array)
Returns a boolean indicating whether a specified value is in an array.static dev.morphia.aggregation.expressions.impls.Expression
indexOfArray(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression search)
Searches an array for an occurrence of a specified value and returns the array index of the first occurernce.static dev.morphia.aggregation.expressions.impls.Expression
isArray(dev.morphia.aggregation.expressions.impls.Expression array)
Determines if the operand is an array.static dev.morphia.aggregation.expressions.impls.MapExpression
map(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression in)
Applies a subexpression to each element of an array and returns the array of resulting values in order.static dev.morphia.aggregation.expressions.impls.Expression
objectToArray(dev.morphia.aggregation.expressions.impls.Expression array)
Converts a document to an array of documents representing key-value pairs.static dev.morphia.aggregation.expressions.impls.RangeExpression
range(int start, int end)
Outputs an array containing a sequence of integers according to user-defined inputs.static dev.morphia.aggregation.expressions.impls.Expression
reduce(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression initial, dev.morphia.aggregation.expressions.impls.Expression in)
Applies an expression to each element in an array and combines them into a single value.static dev.morphia.aggregation.expressions.impls.Expression
reverseArray(dev.morphia.aggregation.expressions.impls.Expression array)
Returns an array with the elements in reverse order.static dev.morphia.aggregation.expressions.impls.Expression
size(dev.morphia.aggregation.expressions.impls.Expression array)
Counts and returns the total number of items in an array.static dev.morphia.aggregation.expressions.impls.Expression
slice(dev.morphia.aggregation.expressions.impls.Expression array, int size)
Returns a subset of an array.static dev.morphia.aggregation.expressions.impls.Expression
sortArray(dev.morphia.aggregation.expressions.impls.Expression input, Sort... sort)
Sorts an array based on its elements.static dev.morphia.aggregation.expressions.impls.ZipExpression
zip(dev.morphia.aggregation.expressions.impls.Expression... arrays)
Merge two arrays together.
-
-
-
Method Detail
-
array
public static dev.morphia.aggregation.expressions.impls.ArrayExpression array(dev.morphia.aggregation.expressions.impls.Expression... expressions)
Creates an array of the given expressions. This "expression" isn't so much a mongodb expression as it is a convenience method for building pipeline definitions.- Parameters:
expressions
- the expressions- Returns:
- the new expression
-
array
@MorphiaExperimental public static dev.morphia.aggregation.expressions.impls.ArrayExpression array(Object... objects)
Creates an array of the given objects. This method is an experiment in accepting a wider breadth of types and finding the expressions at encoding time and dealing with them appropriately. There might be bugs in this approach. This method might go away. But it's useful in some Morphia tests, at least.- Parameters:
objects
- the objects- Returns:
- the new expression
- Since:
- 2.3
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
arrayToObject
public static dev.morphia.aggregation.expressions.impls.Expression arrayToObject(dev.morphia.aggregation.expressions.impls.Expression array)
Converts an array of key value pairs to a document.- Parameters:
array
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $arrayToObject
-
concatArrays
public static dev.morphia.aggregation.expressions.impls.Expression concatArrays(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression additional)
Concatenates arrays to return the concatenated array.- Parameters:
array
- the array to useadditional
- any additional arrays to concatenate- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $concatArrays
-
elementAt
public static dev.morphia.aggregation.expressions.impls.Expression elementAt(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression index)
Returns the element at the specified array index.- Parameters:
array
- the array to useindex
- the index to return- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $arrayElemAt
-
filter
public static dev.morphia.aggregation.expressions.impls.ArrayFilterExpression filter(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression conditional)
Selects a subset of the array to return an array with only the elements that match the filter condition.- Parameters:
array
- the array to useconditional
- the conditional to use for filtering- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $filter
-
in
public static dev.morphia.aggregation.expressions.impls.Expression in(dev.morphia.aggregation.expressions.impls.Expression search, dev.morphia.aggregation.expressions.impls.Expression array)
Returns a boolean indicating whether a specified value is in an array.- Parameters:
search
- the expression to search forarray
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $in
-
indexOfArray
public static dev.morphia.aggregation.expressions.impls.Expression indexOfArray(dev.morphia.aggregation.expressions.impls.Expression array, dev.morphia.aggregation.expressions.impls.Expression search)
Searches an array for an occurrence of a specified value and returns the array index of the first occurernce. If the substring is not found, returns -1.- Parameters:
array
- the array to usesearch
- the expression to search for- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $indexOfArray
-
isArray
public static dev.morphia.aggregation.expressions.impls.Expression isArray(dev.morphia.aggregation.expressions.impls.Expression array)
Determines if the operand is an array. Returns a boolean.- Parameters:
array
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $isArray
-
map
public static dev.morphia.aggregation.expressions.impls.MapExpression map(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression in)
Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters.- Parameters:
input
- the array to usein
- An expression that is applied to each element of the input array.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $map
-
objectToArray
public static dev.morphia.aggregation.expressions.impls.Expression objectToArray(dev.morphia.aggregation.expressions.impls.Expression array)
Converts a document to an array of documents representing key-value pairs.- Parameters:
array
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $objectToArray
-
range
public static dev.morphia.aggregation.expressions.impls.RangeExpression range(int start, int end)
Outputs an array containing a sequence of integers according to user-defined inputs.- Parameters:
start
- the starting valueend
- the ending value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $range
-
reduce
public static dev.morphia.aggregation.expressions.impls.Expression reduce(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression initial, dev.morphia.aggregation.expressions.impls.Expression in)
Applies an expression to each element in an array and combines them into a single value.- Parameters:
input
- the array to useinitial
- The initial cumulative value set before in is applied to the first element of the input array.in
- A valid expression that $reduce applies to each element in the input array in left-to-right order.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $reduce
-
reverseArray
public static dev.morphia.aggregation.expressions.impls.Expression reverseArray(dev.morphia.aggregation.expressions.impls.Expression array)
Returns an array with the elements in reverse order.- Parameters:
array
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $reverseArray
-
size
public static dev.morphia.aggregation.expressions.impls.Expression size(dev.morphia.aggregation.expressions.impls.Expression array)
Counts and returns the total number of items in an array.- Parameters:
array
- the array to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $size
-
slice
public static dev.morphia.aggregation.expressions.impls.Expression slice(dev.morphia.aggregation.expressions.impls.Expression array, int size)
Returns a subset of an array.- Parameters:
array
- the array to usesize
- the number of elements to return- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $slice
-
sortArray
public static dev.morphia.aggregation.expressions.impls.Expression sortArray(dev.morphia.aggregation.expressions.impls.Expression input, Sort... sort)
Sorts an array based on its elements. To sort by value, useSort.naturalAscending()
orSort.naturalDescending()
. See here for details.- Parameters:
input
- the array to be sorted.sort
- the sort order- Returns:
- the new expression
- Since:
- 2.3
- MongoDB documentation
- Aggregration Expression: $sortArray
- Since server release
- 5.2
-
zip
public static dev.morphia.aggregation.expressions.impls.ZipExpression zip(dev.morphia.aggregation.expressions.impls.Expression... arrays)
Merge two arrays together.- Parameters:
arrays
- the arrays to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $zip
-
-