mongoDb: select all users by distance
<p>Im trying to get all of my users according their distance with mongoDb, I just saw I can use "nearSphere" to do it:</p>

<pre><code>{
  $nearSphere: {
     $geometry: {
        type : "Point",
        coordinates : [ &lt;longitude&gt;, &lt;latitude&gt; ]
     },
     $minDistance: &lt;distance in meters&gt;,
     $maxDistance: &lt;distance in meters&gt;
  }
}
</code></pre>

<p>This is my Function:</p>

<pre><code>function getUsersByDistance(req, res, next) {
var range = req.params.distance; //(For example: 3000)
          console.log("Searching for users that far away from me in: " + req.params.distance + "Km");

    //First, lets find my latitude and longitude
    User.findOne({_id: req.params.userId}).populate("user").exec(function (err, user) {
                if (err) {
                    res.jsonp({error: "Error fetching user info"})
                } else {
                    if (!user) {
                        res.jsonp({error: "User not found"});
                    } else {
    //Found it!
        //user.latitude = x
        //user.longitude = y

    //Now I need to fins all users within the range (HERE I NEED YOUR HELP):
    var query = //"{ distance is maximum Z distance from my position }"

    //Then, search all users inside this range:
            Users
                .find(query)
                .sort('-created')
                .exec(function (err, questions) {
                    if (err) {
                        return res.send({
                            errors: err
                        });
                    } else {
                        //Here I should have all users with maximum distance Z from my position
        res.jsonp(users: users);
                    }
                });
        }
</code></pre>

<p>Please help me, Im desperate ...</p>

<p>Thank you!</p>

<p>Eran.</p>