I have a SpringBoot application with REST controller and I need to do sorting by entity properties including map values.
Here is my entity class:
@Document
data class Event(
@Id
val id: CompoundId,
@Indexed
val timestamp: Instant,
val description: String,
val values: Map<String, Any> = HashMap()
)
My REST controller GET:
@GetMapping("/")
fun getEvents(
@PageableDefault(sort = ["timestamp"], direction = Sort.Direction.ASC)
pageable: Pageable?
): Collection<Event> = mongoRepository.find(pageable)
Also, I use MongoDB:
override fun find(pageable: Pageable?): Collection<Event> {
Query().apply {
pageable?.let { with(pageable) }
return mongoTemplate.find(this, Event::class.java)
}
}
I am trying to make requests like this: http://localhost:8080?sort=values,DESC
and I see that order is changed, but I can't understand which parameters it sorted.
Is it possible to sort by map parameters with Pageable
, like http://localhost:8080?sort=values.someKeyInTheMap,DESC
?