title: How to speed up mongodb geo queries with multiple criteria?
body: <h3>Status:</h3>
  
  <p>As far as I understand from reading the mongodb documentation and also playing with indexes, queries and monitoring results, my understanding of the way geo location queries in mongodb work is the following:</p>
  
  <ul>
  <li>Start at the given location</li>
  <li>look at EVERY document from close to far</li>
  <li>keep those matching additional query criteria
  until either <code>number_limit</code> or <code>distance_limit</code> is reached</li>
  </ul>
  
  <h3>Example</h3>
  
  <p>To show what we are trying to do: Let's take the mongodb tutorial example as a base: <a href="https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/" rel="nofollow noreferrer">https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/</a></p>
  
  <p>Let's assume we have a list of restaurants with location and much more information on top, like <code>established_at</code>, <code>type</code> (chinese, thai, italian, ...), <code>priceOfACoke</code>, <code>numberOfWaiters</code>, <code>wheelchairAccess</code>, ...</p>
  
  <h3>Problem:</h3>
  
  <p>Let's assume you want to query the collection of all restaurants in the US of A to return all Italian restaurants close to the city center of Pittsburgh that have been established between 2-5 years ago, with wheelChair access and more than 50 waiters, where a coke is cheaper than 1$.</p>
  
  <p>This is a geo query with with restrictive additional criteria and no distance limit; and since the "waiters>50 an coke cheaper than $1" filters out most/all of the results, this query seems to be running through the whole collection and takes very long.</p>
  
  <p>If run without "geoNear", assuming there is a combined index of the fields in question, this query is quite fast, even if there are only 10 results out of 1 million documents.</p>
  
  <p><strong>However, as soon as <code>geoNear</code> comes into play, the performance is terrible</strong></p>
  
  <p>From what I understand, there can only be ONE geo index per collection and only ONE additional property in the geo index, so there is not much to do to help mongodb finding the results with several criteria, as a traditional index seems not to be used.
  Also, when using aggregate, geo has to be the first filter...</p>
  
  <p><strong>Are there any hints or pointers to speed up queries like this?</strong></p>
  
  <p>If possible, I'd prefer not get "Use ElasticSearch" or "Use multiple collections " responses - I still hope there is another way to help mongodb reduce the number of documents to check BEFORE it starts doing the geoNear part.</p>