spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

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

Open spring-projects-issues opened this issue 9 years ago • 1 comments

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

spring-projects-issues avatar Feb 19 '16 22:02 spring-projects-issues

will there be a fix or do we have a workaround here?

mngphm avatar Mar 15 '21 17:03 mngphm