MongoDB request DSL • opensavvy.ktmongo.dsl.aggregation.operators • StringValueOperators • replaceFirst
replaceFirst¶
Replaces the first instance of find
with a replacement
string.
If no occurrences of find
are found in the input string, the input string is returned. If any of the input, find
or replacement
is null
, null
is returned.
The input, find
, and replacement
expressions must evaluate to a string or a null
, or $replaceOne
fails with an error.
Example¶
class Document(
val item: String,
)
collection.aggregate()
.set {
Document::item set of(Document::item).replaceFirst(find = of("blue paint"), replacement = of("red paint"))
}.toList()
External resources¶
Replaces the first instance of find
with a replacement
string.
If no occurrences of find
are found in the input string, the input string is returned. If the input is null
, null
is returned.
The input must evaluate to a string or a null
, or $replaceOne
fails with an error.
Example¶
class Document(
val item: String,
)
collection.aggregate()
.set {
Document::item set of(Document::item).replaceFirst(find = "blue paint", replacement = "red paint")
}.toList()