0

Using MongoDb and @RepositoryRestController and Pageable from Spring.

Controller method(passing in -- ?page=0&size=20&sort=events.field1,asc):

..WithCreator(@RequestBody ..., @ParameterObject final Pageable page)

I'm having a hard time finding out how to search for a nested array of objects' field using the Spring Pageable object. I can sort in mongo by the array of objects' field. eg.:

 // a document in the db
{
  events:[
    {field1:"Test"}
  ]
}
//can sort the above document like so:
{ "$sort" : {  "events.field1" : -1}}

The problem is, the Pageable object actually looks through the persistent entity and filters out fields that it doesn't find in there. In this case of "events.field1" the Sort object translates to UNSORTED in the end. It does find the "events" field, but that's where it ends.

Question: Is there a way with Pageable around this, other than passing the sort as a separate query field, or am I missing something?

The translation/field filtering of the original "raw" Sort object happens here:

class org.springframework.data.rest.webmvc.json JacksonMappingAwareSortTranslator..

public Sort translateSort(Sort input, PersistentEntity<?, ?> rootEntity){..}
Noel
  • 10,152
  • 30
  • 45
  • 67
Daniel Jeney
  • 486
  • 1
  • 5
  • 19

0 Answers0