Details
-
Improvement
-
Resolution: Won't Fix
-
Major - P3
-
None
-
None
-
None
Description
The options classes define in com.mongodb.client.model use fluent setter methods, so that all options can be set without first assigning an instance of the options class to a variable, e.g.
// Java
|
collection.updateMany(Filters.eq("x", 1), Updates.set("x", 2), |
UpdateOptions()
|
.upsert(true) |
.bypassDocumentValidation(true)); |
This is convenient for Java, but in Kotlin there is a more natural idiom that could be used if each option were exposed as a standard Java Bean-style setter:
// Kotlin
|
collection.updateMany(Filters.eq("x", 1), Updates.set("x", 2), |
UpdateOptions().apply {
|
upsert = true |
collation = Collation.builder().backwards(true).build() |
bypassDocumentValidation = true |
});
|
which makes use of the <T> T.apply(block: T.() -> Unit): T extension function in the Kotlin standard library.