I hope you guys can help. I'm fairly new to node.js / mongodb and i'm having trouble passing in variables to a mongoose model query.
If I run this, passing in the longitude/latitude (-0.18, 51.24) manually as strings then it works perfectly and returns lots of objects from the database.
Venue.find( { location : { $nearSphere : [-0.18, 51.24], $maxDistance : 25/3959 } }, null, {limit: 50}, function(err, results){
results.forEach(function(result){
console.log('Found a record');
});
});
However if I try and pass in these coordinates as variables into the function that this runs in it doesn't return any results:
function generateWorld(get) {
console.log('Generating for x:' + get.longitude + ' y:' + get.latitude); // Console logs correct coords
Venue.find( { location : { $nearSphere : [get.longitude, get.latitude], $maxDistance : 25/3959 } }, null, {limit: 50}, function(err, results){
results.forEach(function(result){
console.log('Found a record'); // <-- This doesn't return any results!
});
});
}
I'm sure I'm just doing something simple wrong but I've been scratching my head over this for a while and can't get past it. Any help would be much appreciated!
Thanks.