title: In MongoDB, is one big $or search faster than multiple single searches?
body: <p>I have a list of about 50 <code>tags</code> in an array, and want to search through my documents to find records that match these tags.</p>
  
  <p>Because they're user-submitted and mongoDB is case-sensitive, I'm using <code>/wildcard/i</code> as a means of searching. I know this is not the fastest way to do a search but I can't think of a better solution.</p>
  
  <p>I can do my query in two ways. The first is to run a <code>for</code> loop over my <code>tags</code> array, and for each result, perform:</p>
  
  <pre><code>db.collection.find({tags: /&lt;tag[x]&gt;/i})
  </code></pre>
  
  <p>Or, I can collect all of the tags and run one single lookup using <code>$or</code>, like so:</p>
  
  <pre><code>db.collection.find({$or:[{tags:/&lt;tag1&gt;/i},{tags:/&lt;tag2&gt;/i},{tags:/&lt;tag3&gt;/i}, ... {tags:/&lt;tag50&gt;/i}]});
  </code></pre>
  
  <p>I have tried both, and found using <code>$or</code> to be significantly faster - but because of the work-in-progress state of my application, it's very difficult to tell whether this is because it's actually faster or whether my app is causing significant overhead in other areas (it is). </p>
  
  <p><strong>So for clarification, in MongoDB is a big query performed once faster than small queries performed many times?</strong></p>
  
  <p>EDIT: Another example would be whether looking up 3 individual records based on <code>_id</code> is faster than doing one lookup using <code>{$or:[{_id: ObjectId([id1])},{_id: ObjectId([id2])},{_id: ObjectId([id3])}]}</code>. Is less more?</p>