Add Java Bean-style setters to options classes

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: