Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my mongoose schema -

var userDestinationSchema = mongoose.Schema({

    uid: String,                
    update_time: Date,          

    location:{                  //<INDEXED as 2d>
        lon: Number,
        lat: Number

var userDestinationModel = mongoose.model('userDestinationModel', userDestinationSchema);

How do I query the model for geoNear?

I tried doing this and it ain't working.

              { maxDistance : 50, spherical : true }, 
              function(err, results, stats) {

maxDistance : 50

What is the unit? Km?

share|improve this question

I can answer the distance part, but I've never used geoNear with Mongoose I'm afraid - a good way to tell if the issue lies in how you are calling things in Mongoose versus the query itself would be to try it on the mongo shell first to verify that it is returning the results you expect there.

In terms of the distance, for legacy 2d points (which you appear to be using), the $maxdistance is specified in radians - there is a page here which outlines how to use radians with spherical geometry calculations. If you use GeoJSON instead (which I would recommend), then it is specified in meters (reference).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.