spring-projects / spring-projects/spring-data-mongodb

Sorting is not working when I'm making findByLocationNear [DATAMONGO-1384]

Open
#2,298 1 comment 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since May 31, 2023.

type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Vladimir T opened DATAMONGO-1384 and commented

Hello

I'd like to rise a sorting issue

This is my method from the Repository

GeoPage<Outlet> findByLocationNearAndTypeAndKeywordsIn(Point p, Distance d, String type, Collection<String> keywords, Pageable pageable);

These are my GET requests

http://localhost:8080/outlets/x/11.111/y/22.2222/distance/1000?sort=name,desc&type=RTL&keywords=dress

http://localhost:8080/outlets/x/11.111/y/22.2222/distance/1000?sort=name,asc&type=RTL&keywords=dress

Have a look please on param of request sort=name,desc and sort=name,asc

I'd like to emphesize that Pageable pageable is mapped on sort param perfect

when I invoke method findByLocationNearAndTypeAndKeywordsIn I find on log following strings:

2016-02-20 00:42:41,566 DEBUG ngodb.repository.query.MongoQueryCreator: 157 - Created query Query: { "type" : "RTL" , "keywords" : { "$in" : [ "dress"]}}, Fields: null, Sort: { "name" : -1}
2016-02-20 00:42:41,570 DEBUG ngodb.repository.query.MongoQueryCreator: 157 - Created query Query: { "location" : { "$nearSphere" : { $java : Point [x=11.1111, y=22.22222] }, "$maxDistance" : 1.567855942887398E-4 }, "type" : "RTL", "keywords" : { "$in" : [ "dress"]} }, Fields: null, Sort: { "name" : -1}
2016-02-20 00:42:41,573 DEBUG framework.data.mongodb.core.MongoDbUtils: 122 - Getting Mongo Database name=[dev_env]
2016-02-20 00:42:41,631 DEBUG framework.data.mongodb.core.MongoDbUtils: 122 - Getting Mongo Database name=[dev_env]
2016-02-20 00:42:41,803 DEBUG ation.RequestResponseBodyMethodProcessor: 225 - Written [[Outlet{id='1', noCode='4410', location=Point [x=11.1111, y=22.22222], name='DR-4410', phone='null', url='null', email='null', type=RTL, keywords=[dress], status=null, desc='null', street='null', rgnCode=null}, Outlet{id='5', noCode='2519', location=Point [x=11.1111, y=22.22222], name='Ad ..', phone='067 555-5555', url='null', email='null', type=RTL, keywords=[dress], status=U, desc='null', street='null', rgnCode=KM7}]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@67319973]

2016-02-20 00:42:41,566 DEBUG ngodb.repository.query.MongoQueryCreator: 157 - Created query Query: { "type" : "RTL" , "keywords" : { "$in" : [ "dress"]}}, Fields: null, Sort: { "name" : 1}
2016-02-20 00:42:41,570 DEBUG ngodb.repository.query.MongoQueryCreator: 157 - Created query Query: { "location" : { "$nearSphere" : { $java : Point [x=11.1111, y=22.22222] }, "$maxDistance" : 1.567855942887398E-4 }, "type" : "RTL", "keywords" : { "$in" : [ "dress"]} }, Fields: null, Sort: { "name" : 1}
2016-02-20 00:42:41,573 DEBUG framework.data.mongodb.core.MongoDbUtils: 122 - Getting Mongo Database name=[dev_env]
2016-02-20 00:42:41,631 DEBUG framework.data.mongodb.core.MongoDbUtils: 122 - Getting Mongo Database name=[dev_env]
2016-02-20 00:42:41,803 DEBUG ation.RequestResponseBodyMethodProcessor: 225 - Written [[Outlet{id='1', noCode='4410', location=Point [x=11.1111, y=22.22222], name='DR-4410', phone='null', url='null', email='null', type=RTL, keywords=[dress], status=null, desc='null', street='null', rgnCode=null}, Outlet{id='5', noCode='2519', location=Point [x=11.1111, y=22.22222], name='Ad ..', phone='067 555-5555', url='null', email='null', type=RTL, keywords=[dress], status=U, desc='null', street='null', rgnCode=KM7}]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@67319973]

As far as you see the order is not changed even when the Sort value is different

Native query with sorting to mongodb works perfect.
Something like this:

db.outlets.find({$and:[ { location :
{ $near :
{ $geometry :
{ type : "Point" ,
coordinates : [ 11.1111 , 22.2222 ] } ,
$maxDistance : 1000
} } }, {type:"RTL"}]}).sort({
"name": 1
})


No further details from DATAMONGO-1384

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.