Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.operatorsStringValueOperatorstrimStart

trimStart

Removes whitespace characters, including null, or the specified characters from the beginning of a string.

By default, removes whitespace characters including the null character.

Example

class Document(
    val text: String,
)

collection.aggregate()
    .set {
        Document::text set of(Document::text).trimStart()
    }.toList()

External resources

open fun <Context : Any> Value<Context, String?>.trimStart(vararg characters: Char): Value<Context, String?>

Removes the specified characters from the beginning of a string.

Example

class Document(
    val text: String,
)

// Trim both 'g' and 'e' characters from the beginning
collection.aggregate()
    .set {
        Document::text set of(Document::text).trimStart('g', 'e')
    }.toList()

// Trim space, 'g', and 'e' characters from the beginning
collection.aggregate()
    .set {
        Document::text set of(Document::text).trimStart(' ', 'g', 'e')
    }.toList()

External resources

open fun <Context : Any> Value<Context, String?>.trimStart(characters: Value<Context, String?>): Value<Context, String?>

Removes the specified characters from the beginning of a string.

The characters parameter is a single string that can contain multiple characters to be trimmed. Each character in the string will be removed from the beginning of the input string.

Example

class Document(
    val text: String,
)

// Trim both 'g' and 'e' characters from the beginning
collection.aggregate()
    .set {
        Document::text set of(Document::text).trimStart(characters = of("ge"))
    }.toList()

// Trim space, 'g', and 'e' characters from the beginning
collection.aggregate()
    .set {
        Document::text set of(Document::text).trimStart(characters = of(" ge"))
    }.toList()

External resources