Passing variables into node.js mongoose find query

Problem

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.

Problem courtesy of: Paul Maddox

Solution

Try to do get.longitude = parseFloat(get.longitude) and get.latitude = parseFloat(get.latitude).

Solution courtesy of: alessioalex

Discussion

You could also just put a '+' sign in front of each variable to coerce them to numbers, i.e.,

{ $nearSphere : [+get.longitude, +get.latitude]

Works even if one of the variables is negative.

Discussion courtesy of: danmactough

This recipe can be found in it's original form on Stack Over Flow.