MongoDB geospatial: how to find if a point is within range from any other point : <p>I'm struggling with completing this query but maybe I'm using the wrong approach. Right now I'm doing it like this:</p>

<pre><code>db.cells.find(
   {
     loc: {
        $nearSphere: {
           $geometry: {
              type : "Point",
              coordinates : [ 31.0, 31.0 ]
           },
           $minDistance: 0,
           $maxDistance: $range
        }
     }
   }
)         
</code></pre>

<p>Here <code>$range</code> should be a field of my document but in a previous answer they told me that there is no option to do that in MongoDB.</p>

<p>So I would like to retrieve all the documents where the field <code>loc</code> is a point within distance inferior to field <code>range</code>. Is it possible to do it with a single query? I can restructure the document format if necessary.</p>

<p>Thanks</p>
