title: Search suggestions: Insanely slow Mongo retrieval time
body: <p>I'm trying to implement real-time search suggestions on an input field. Retrieval time takes an average of 1500ms, and occasionally 3000ms+ for a collection of 23 documents. </p>
  
  <p>This is running on MongoLab's Sandbox tier with "variable" RAM; AWS EC2 T2.Medium. </p>
  
  <p>The relevant field of the data model is indexed (using Mongoose). Here's my query for retrieval.</p>
  
  <pre><code>model_user.find(
      { 'profile.local.displayName' : new RegExp( '^' + req.query.input, 'i') }
    , { 'profile.local.displayName' : 1, 'profile.local.photo' : 1 }) // photo is a url string
  .limit(6)
  .lean()
  .exec(function (err, data) {
    if (err) return next(err);
    next(data);
  }); // end exec
  </code></pre>
  
  <p>Is this normal for Mongo? Should I not be using <code>.find()</code> cursor for realtime search suggestions? If so, what else should I use instead?</p>
  
  <p><i>Edit (8:52pm PT): Just upgraded to shared multi-node replica set on MongoLab. No change in query speed.</i></p>
  
  <p><i>Edit (9:13pm PT): Correction for the previous edit, new speed is 550ms-650ms on the multi-node cluster</i></p>
  
  <p><i>Edit (9:56pm PT): @jsh I'm not too familiar with .explain() and the console is telling me that it's not a function. According to <a href="https://stackoverflow.com/questions/17506002/how-to-find-nscanned-in-mongoose">this post</a> turning on Mongoose debugger is equivalent, so here's the output (unformatted from the direct copy). </p>
  
  <pre><code>Mongoose: users.find({ 'profile.local.displayName': /^Daniel/i }) { limit: 6, fields: { 'profile.local.displayName': 1, 'profile.local.photo': 1 } }  
  GET   [A] /api/search/username?input=Daniel           200 3.317s
  </code></pre>
  
  <p></i></p>