CastError on nearSphere query #1874

ghartnett opened this Issue Jan 13, 2014 · 5 comments


None yet

6 participants


This issue is based on an issue reported in:

I reproduced the problem & worked around it by using legacy coordinates.

I think the problem is in lib/query.js

On mongoose 3.8.3 I changed
} else if (('$near' == geo || '$geoIntersects' == geo) &&
} else if (('$near' == geo || '$nearSphere' == geo || '$geoIntersects' == geo) &&

And it worked for me.


thanks for the detailed report.

omarojo commented Apr 14, 2014

Has this issue being fixed by now ?? I am having it ... I can't proceed with my project.. I must not use legacy coordinates because of the 100 documents return limit. I need to use geoJSON... BTW using @ghartnett changes in query.js code.. didn't change anything.. it just omits the error message..

cuixu66 commented Jun 7, 2014

Encountered the same issue.
@ghartnett Your changes worked for me. (At line 2221 in query.js).
My query code is in the following form:

Model.find({loc: { '$nearSphere': {'$geometry': { type: 'Point', coordinates: [ -81.1982134, 42.7788049]}, $maxDistance: 10}}});
@vkarpov15 vkarpov15 added this to the 3.8.13 milestone Jun 10, 2014
epegzz commented Jun 19, 2014

Half a year later, bug still not fixed ) :

@vkarpov15 vkarpov15 added a commit that closed this issue Jun 27, 2014
@vkarpov15 vkarpov15 Fix #1874 295fc32
@vkarpov15 vkarpov15 closed this in 295fc32 Jun 27, 2014
@vkarpov15 vkarpov15 removed the bug? label Jun 27, 2014

Fixed, will be in 3.8.13. FWIW, the original bug reported by @ghartnett was primarily caused by running a nearSphere on the wrong field, but it did expose this underlying problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment