title: MongoDB 'near' geospatial query of array of GeoJSON polygons
body: <p>What I would like to do is a have a query which finds documents which have <strong>a</strong> volume (any point in the volume) which is within some distance. I sadly cannot modify the document structure which I am using without a pretty major overhaul. I can implement this on the application side, but that would require a large data transfer.</p>
  
  <p>I have a document which contains data in this format:</p>
  
  <pre><code>{  
     "volumes":[  
        {  
           "volume":{  
              "type":"Polygon",
              "coordinates":[  
                 [  
  
                 ]
              ]
           }
        }
     ]
  }
  </code></pre>
  
  <p>Example query which will not work:</p>
  
  <pre><code>{  
     'volumes.volume':{  
        '$geoWithin':{  
           '$centerSphere':[  
              [  
                 0,
                 0
              ],
              3.14159
           ]
        }
     }
  }
  </code></pre>
  
  <p>This sort of does what I want, but does 'within' instead of 'intersects', also I don't believe that it would work with <strong>any</strong> volume, but only if all volumes (correct me if I'm wrong) are within.</p>
  
  <p>I may let my ignorance show a bit here but in general the optimum query would do something like (although I'm aware this wouldn't work):</p>
  
  <pre><code>{  
     'volumes':{  
        '$elemMatch':{  
           'volume':{  
              '$near':{  
                 '$geometry':reference_point,
                 '$maxDistance':distance
              }
           }
        }
     }
  }
  </code></pre>