Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5308

Filters support for Dataclass properties

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Kotlin
    • Labels:
      None
    • Java Drivers
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      That we now support Filters for Dataclass properties

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Yes, in the Serialization section.

      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? That we now support Filters for Dataclass properties 2. Would you like the user to see examples of the syntax and/or executable code and its output? Yes, in the Serialization section. 3. Which versions of the driver/connector does this apply to?

      Can we add Filters support for Dataclass properties?

      We have heard from a customer that find() does not support @SerialName annotations, but that insertOne() does. A related community forums ticket as well: https://www.mongodb.com/community/forums/t/nested-data-class-filters/239472.

      @Serializable
      data class ListDto(
          @Contextual @SerialName("_id") val id: Id<ListDto> = ObjectId().toId(),
          @Contextual var userId: Id<UserDto>,
          var name: String,
          val categories: MutableList<CategoryDto> = mutableListOf(),
          var icon: String, // Single emoji at the moment
          var color: String // Represented as #RRGGBB hex color
      )
      
      @Serializable
      data class CategoryDto(
          @Contextual @SerialName("_id") val id: Id<CategoryDto> = ObjectId().toId(),
          var name: String,
          var color: String // Represented as #010101 hex color
      )
      

      What I need to do is update a single property (for example the name) in one of the categories items, filtering via the id.

      In Kmongo I was using

      return col.findOneAndUpdate(
                  and(ListDto::id eq listId, ListDto::userId eq userId, (ListDto::categories / CategoryDto::id) eq categoryId),
                  set(*properties.toTypedArray()),
                  FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
              )
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ashni.mehta@mongodb.com Ashni Mehta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: