I am working on a small module which deals with the nearby documents for given spherical lookup. While working with mongoid3 I used the following to receive documents with given latitude, longitude and spherical distance to lookup the documents.
document_klass.within_spherical_circle(geo_attribute: [[77.04363, 28.45842], (20.fdiv(6371))])
Gives the result of documents within the 20 kms sphere from the latlong given. Also I can apply limit and pagination on this as this is a pure mongoid criteria.
But the result of this doesn't give documents in the sorted order by default. (and also I am unable to find any option with within_spherical_circle which gives me documents sorted via distance) I also tried geo_near method but with that its hard to do pagination/skip. Any suggestions?
UPDATE
Also, I tried mongoid 3.1.x geo_near method as
document_class.limit(10).geo_near([77.04363, 28.45842]).distance_multiplier(6371).max_distance(10.fdiv(6371)).spherical
which suppose to give me the result in sorted order and its doing exactly the same.
[0.0, 0.013106917278934711, 0.014252314759648424, 0.01842674324658152, 0.02131271009525241, 0.022594202024593005, 0.024637859034323726, 0.02501954892893619, 0.02501954892893619, 0.025071008433970268]
But this doesn't not consider, page for mongodb $skip thing.