title: MongoDB: How to perform spatial queries on nested location properties?
body: <p>I have a document structure like this:</p>
  
  <pre><code>{
      name: "John",
      addresses: [
          {
              city: "London",
              location: {
                  type: "Point",
                  coordinates: [0, 0]
              }
          },
          {
              city: "New York",
              location: {
                  type: "Point",
                  coordinates: [-74, 40]
              }
          }
      ]
  },
  {
      name: "Joanna",
      addresses: [
          // Similar array of her addresses
      ]
  }
  </code></pre>
  
  <p>Now, I have a coordinate <code>x = (0.0001, 0.0001)</code>. I want to get all the people in my collection that have an address close to this point <strong>and get only those addresses in the response</strong>. For the query coordinate as <code>x</code>, I want only John's first address in the response:</p>
  
  <pre><code>{
      name: "John",
      addresses: [
          {
              city: "London",
              location: {
                  type: "Point",
                  coordinates: [0, 0]
              }
          }
      ]
  }
  </code></pre>
  
  <p>I have seen similar examples, but they all return the entire document, i.e. they'd return all of John's addresses. How do I return only the <strong>addresses</strong> (there may be more than one, hence the <code>$</code> operator won't work), that are near the query coordinate <code>x</code>?</p>
  
  <p>P.S. - I did try unwinding and then checking (using the aggregation framework), but that doesn't allow me to use a spatial query anywhere else except for the first stage of the pipeline.</p>