Is there any morphia query to achieve $geoWithin and $centerSphere mongo Operations?

StackOverflow https://stackoverflow.com/questions/18657459

  •  27-06-2022
  •  | 
  •  

Question

The existing Morphia Query:

q.field("somefield").within(addressLatLng.getLat(), addressLatLng.getLng(), degrees);  

which gives a Mongo query like

{ "geo" : 
 { "$within" : 
  { "$center" :
    [ [ 38.8987037 , -81.52672820000001] , 4.341534008683068E7]
}}}

But this makes our application slow on loadtest, it takes around 400ms to execute, whereas the Query with mongo operations $geoWithin and $centerSphere query execute much faster about 9ms.

This the Mongo Query:

{ geo: 
 {$geoWithin: 
  { $centerSphere: [ [ 42.0494171, -80.0423151 ], 0.00758341759353 ]
}} } --- 

I need a morphia query for the above stated Mongo Query, I have searched in morphia's documentation but there is no such API for $geoWithin and $center.

Was it helpful?

Solution

For those following this one, this is the issue filed on this request: https://github.com/mongodb/morphia/issues/522

-- Update 9/11:

I just pushed a fix for this: https://github.com/mongodb/morphia/issues/522

-- Update 9/12

Version 0.104 with this fix has just been released: https://github.com/mongodb/morphia/releases/tag/0.104

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top