Class StringExpressions

java.lang.Object
dev.morphia.aggregation.expressions.StringExpressions

public final class StringExpressions extends Object
Defines helper methods for the string expressions
Since:
2.0
  • Method Details

    • concat

      public static Expression concat(Object first, Object... additional)
      Concatenates any number of strings.
      Parameters:
      first - the first array expression
      additional - additional expressions
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $concat
    • indexOfBytes

      public 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. If the substring is not found, returns -1.
      Parameters:
      string - the string to search
      substring - the target string
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $indexOfBytes
    • indexOfCP

      public static IndexExpression indexOfCP(Object string, Object substring)
      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 search
      substring - the target string
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $indexOfCP
    • ltrim

      public static TrimExpression ltrim(Object input)
      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

      public static RegexExpression regexFind(Object input)
      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

      public static RegexExpression regexFindAll(Object input)
      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

      public 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.
      Parameters:
      input - the string to process
      Returns:
      the new expression
      Since server release
      4.2
      MongoDB documentation
      Aggregration Expression: $regexMatch
    • replaceAll

      public static Expression replaceAll(Object input, Object find, Object replacement)
      Replaces all instances of a search string in an input string with a replacement string.
      Parameters:
      input - the input value/source
      find - the search expression
      replacement - the replacement value
      Returns:
      the new expression
      Since:
      2.1
      Since server release
      4.4
      MongoDB documentation
      Aggregration Expression: $replaceAll
    • replaceOne

      public 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.
      Parameters:
      input - the input value/source
      find - the search expression
      replacement - the replacement value
      Returns:
      the new expression
      Since:
      2.1
      Since server release
      4.4
      MongoDB documentation
      Aggregration Expression: $replaceOne
    • rtrim

      public static TrimExpression rtrim(Object input)
      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

      public static Expression split(Object input, Object delimiter)
      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

      public static Expression strLenBytes(Object input)
      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

      public static Expression strLenCP(Object input)
      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

      public 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.
      Parameters:
      first - the first string to compare
      second - the first string to second
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $strcasecmp
    • substrBytes

      public static Expression substrBytes(Object input, int start, int length)
      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 process
      start - Indicates the starting point of the substring
      length - 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

      public static Expression substrBytes(Object input, Object start, Object length)
      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 process
      start - Indicates the starting point of the substring
      length - 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

      public static Expression substrCP(Object input, Object start, Object length)
      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 process
      start - Indicates the starting point of the substring
      length - the code points to include.
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $substrCP
    • toLower

      public static Expression toLower(Object input)
      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

      public static Expression toString(Object input)
      Converts value to a string.
      Parameters:
      input - the value to process
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $toString
    • toUpper

      public static Expression toUpper(Object input)
      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

      public static TrimExpression trim(Object input)
      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