I'm not able to run the geoNear query on my Mongo collection through mongoose. My schema looks like this: [1]: https://i.stack.imgur.com/rc0n5.jpg "schema". This is a screenshot of my indexes : [2]: https://i.stack.imgur.com/8qbGR.jpg "indexes".
var url = 'mongodb://*******';
MongoClient.connect(url, function(err, db) {
if(err) {
res.sendStatus(500)
} else {
if(db.places) {
console.log("Connected successfully to server");
var response = db.places.find({ coordinates : { $near : { $geometry : {
type : "Point" ,
coordinates : [req.query.lomg, req.query.lat] },
$maxDistance : 10000 /* 10 kms */
}
}
})
res.send(response)
}
res.sendStatus(500);
}
});
The code is erroring out and always going to the else block thereby returning 500.