Reputation: 4328
I have to locate all the places near a point (GeoJson). I can easily use near
method on the Model to find them.
But, I also need the distances from the current location to be stored in the final output as a virtual property.
I believe I should use geoNear command somewhere but I am a complete noob to MongoDB or mongoose(I'm using v4) and do not know what commands are or how to use them (particularly in mongoose).
Upvotes: 2
Views: 2701
Reputation: 938
You should use aggregate near. Example:
mongoose.model('ModelName').aggregate().near({
near: [lng, lat],
distanceField: 'distance'
})
Upvotes: 3