Will
Will

Reputation: 410

SpringDataMongo MongoRepository pageable not sorted with geo-spatial method

I am facing a problem with sorting from Pageable with geo-spatial method in MongoRepository

With the following code I am able to retrieve first requestVo.per_page records when requestVo.page is 0. However the list is not sorted by title.

Another thing I have noticed is that the same PageRequest object is able to give me the sorted pageable list with photoRepository.findAll. Any help is appreciated!

    LinkedList<Photo> photos= new LinkedList<Photo>();
    PageRequest request = new PageRequest(requestVo.page, requestVo.per_page,Direction.ASC,"title");
    for (GeoResult<Photo> photoResult : photoRepository.findByLocationNear(point, distance,request).getContent()) {
        photos.add(photoResult.getContent());
    }
    return photos;

Upvotes: 1

Views: 517

Answers (1)

Will
Will

Reputation: 410

Turns out that GeoResult is blocking the sorting. Working perfect when I just return collection of Photo.

    LinkedList<Photo> photos= new LinkedList<Photo>();
    PageRequest request = new PageRequest(requestVo.page, requestVo.per_page,Direction.ASC,"title");
    for (Photo photoResult : photoRepository.findByLocationNear(point, distance,request)) {
        photos.add(photoResult);
    }
    return photos;

Upvotes: 2

Related Questions