Take the 2-minute tour ×
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.

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.

userDestinationModel.geoNear([parseInt(req.params.lon,10),parseInt(req.params.lat,10)],
              { maxDistance : 50, spherical : true }, 
              function(err, results, stats) {
                   console.log(results);
                });

maxDistance : 50

What is the unit? Km?

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.