Class StringExpressions
java.lang.Object
dev.morphia.aggregation.expressions.StringExpressions
Defines helper methods for the string expressions
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Expression
Concatenates any number of strings.static IndexExpression
indexOfBytes
(Object string, Object substring) Searches a string for an occurrence of a substring and returns the UTF-8 byte index of the first occurrence.static IndexExpression
Searches a string for an occurrence of a substring and returns the UTF-8 code point index of the first occurrence.static TrimExpression
Removes whitespace or the specified characters from the beginning of a string.static RegexExpression
Applies a regular expression (regex) to a string and returns information on the first matched substring.static RegexExpression
regexFindAll
(Object input) Applies a regular expression (regex) to a string and returns information on the all matched substrings.static RegexExpression
regexMatch
(Object input) Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not.static Expression
replaceAll
(Object input, Object find, Object replacement) Replaces all instances of a search string in an input string with a replacement string.static Expression
replaceOne
(Object input, Object find, Object replacement) Replaces the first instance of a search string in an input string with a replacement string.static TrimExpression
Removes whitespace or the specified characters from the end of a string.static Expression
Splits a string into substrings based on a delimiter.static Expression
strcasecmp
(Object first, Object second) Performs case-insensitive string comparison and returns: 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.static Expression
strLenBytes
(Object input) Returns the number of UTF-8 encoded bytes in a string.static Expression
Returns the number of UTF-8 code points in a string.static Expression
substrBytes
(Object input, int start, int length) Returns the substring of a string.static Expression
substrBytes
(Object input, Object start, Object length) Returns the substring of a string.static Expression
Returns the substring of a string.static Expression
Converts a string to lowercase.static Expression
Converts value to a string.static Expression
Converts a string to uppercase.static TrimExpression
Removes whitespace or the specified characters from the beginning and end of a string.
-
Method Details
-
concat
Concatenates any number of strings.- Parameters:
first
- the first array expressionadditional
- additional expressions- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $concat
-
indexOfBytes
Searches a string for an occurrence of a substring and returns the UTF-8 byte index of the first occurrence. If the substring is not found, returns -1.- Parameters:
string
- the string to searchsubstring
- the target string- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $indexOfBytes
-
indexOfCP
Searches a string for an occurrence of a substring and returns the UTF-8 code point index of the first occurrence. If the substring is not found, returns -1- Parameters:
string
- the string to searchsubstring
- the target string- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $indexOfCP
-
ltrim
Removes whitespace or the specified characters from the beginning of a string.- Parameters:
input
- The string to trim. The argument can be any valid expression that resolves to a string.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $ltrim
-
regexFind
Applies a regular expression (regex) to a string and returns information on the first matched substring.- Parameters:
input
- the string to evaluate- Returns:
- the new expression
- Since server release
- 4.2
- MongoDB documentation
- Aggregration Expression: $regexFind
-
regexFindAll
Applies a regular expression (regex) to a string and returns information on the all matched substrings.- Parameters:
input
- the string to evaluate- Returns:
- the new expression
- Since server release
- 4.2
- MongoDB documentation
- Aggregration Expression: $regexFindAll
-
regexMatch
Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not.- Parameters:
input
- the string to process- Returns:
- the new expression
- Since server release
- 4.2
- MongoDB documentation
- Aggregration Expression: $regexMatch
-
replaceAll
Replaces all instances of a search string in an input string with a replacement string.- Parameters:
input
- the input value/sourcefind
- the search expressionreplacement
- the replacement value- Returns:
- the new expression
- Since:
- 2.1
- Since server release
- 4.4
- MongoDB documentation
- Aggregration Expression: $replaceAll
-
replaceOne
Replaces the first instance of a search string in an input string with a replacement string.- Parameters:
input
- the input value/sourcefind
- the search expressionreplacement
- the replacement value- Returns:
- the new expression
- Since:
- 2.1
- Since server release
- 4.4
- MongoDB documentation
- Aggregration Expression: $replaceOne
-
rtrim
Removes whitespace or the specified characters from the end of a string.- Parameters:
input
- The string to trim. The argument can be any valid expression that resolves to a string.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $rtrim
-
split
Splits a string into substrings based on a delimiter. Returns an array of substrings. If the delimiter is not found within the string, returns an array containing the original string.- Parameters:
input
- The string to split. The argument can be any valid expression that resolves to a string.delimiter
- The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $split
-
strLenBytes
Returns the number of UTF-8 encoded bytes in a string.- Parameters:
input
- the string to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $strLenBytes
-
strLenCP
Returns the number of UTF-8 code points in a string.- Parameters:
input
- the string to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $strLenCP
-
strcasecmp
Performs case-insensitive string comparison and returns: 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.- Parameters:
first
- the first string to comparesecond
- the first string to second- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $strcasecmp
-
substrBytes
Returns the substring of a string. Starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the specified number of bytes.- Parameters:
input
- the string to processstart
- Indicates the starting point of the substringlength
- the byte count to include. Can not result in an ending index that is in the middle of a UTF-8 character.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $substrBytes
-
substrBytes
Returns the substring of a string. Starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the specified number of bytes.- Parameters:
input
- the string to processstart
- Indicates the starting point of the substringlength
- the byte count to include. Can not result in an ending index that is in the middle of a UTF-8 character.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $substrBytes
-
substrCP
Returns the substring of a string. Starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string and continues for the number of code points specified.- Parameters:
input
- the string to processstart
- Indicates the starting point of the substringlength
- the code points to include.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $substrCP
-
toLower
Converts a string to lowercase. Accepts a single argument expression.- Parameters:
input
- the string to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $toLower
-
toString
Converts value to a string.- Parameters:
input
- the value to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $toString
-
toUpper
Converts a string to uppercase. Accepts a single argument expression.- Parameters:
input
- the string to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $toUpper
-
trim
Removes whitespace or the specified characters from the beginning and end of a string.- Parameters:
input
- the string to process- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $trim
-