title: Mongodb query by regular expression
body: <p>I use Mongodb to store list of locations over the world, with more than 2M records. Each record is an object like this:</p>
  
  <pre><code>{ "_id" : ObjectId("4e5b339feee76320ab26f930"), "city" : "New York", "longitude" : -87.2008333, "latitude" : 30.8383333, "country_code" : "US", "country_name" : "United States" }
  </code></pre>
  
  <p>I want to perform the search to get out all "CITIES" contain "New York", it took me about 10 seconds to have the result (it is unacceptable in my web system). I have indexed the "city" using ensureIndex() function, but the query is still slow.</p>
  
  <p>Here is my query:</p>
  
  <pre><code>db.locations.find({"city": { "$regex": "(New York)", "$options": 'i' }})
  </code></pre>
  
  <p>I guess the problem is the "regular expression". Can you suggest me a solution for this to get the query result within 2-3 seconds (I have more than 4M records in MySQL, the similar query took me only 1-2 seconds - with indexes).</p>
  
  <p>Thanks and regards.</p>