Skip to content


Subversion checkout URL

You can clone with
Download ZIP


CastError on nearSphere query #1874

ghartnett opened this Issue · 5 comments

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.


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..


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

Half a year later, bug still not fixed ) :

@vkarpov15 vkarpov15 closed this issue from a commit
@vkarpov15 vkarpov15 Fix #1874 295fc32
@vkarpov15 vkarpov15 closed this in 295fc32
@vkarpov15 vkarpov15 removed the bug? label

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
Something went wrong with that request. Please try again.