title: Mongodb performance of $in with single array element vs. $eq
body: <p>In our code, for convenience, we use queries like</p>
  
  <pre><code>db.collection.find({ "field": { $in: array } })
  </code></pre>
  
  <p>even if <code>array</code> contains only a single element. We could have rewritten it in this case to simply be</p>
  
  <pre><code>db.collection.find({ "field": "element" })
  </code></pre>
  
  <p>We thought that these queries would behave the same, however we noticed that with complex queries, that contain <code>$or</code> operators and multiple fields, while <code>explain()</code> shows the same query plan for both cases, actually running the queries returns quickly for the simple case, while using <code>$in</code> takes forever because maybe it's using different index scans.</p>
  
  <p>Why wouldn't the mongodb query compiler turn <code>$in</code> with a single element into the same as <code>$eq</code>? And why would <code>explain()</code> still show that they're using the same index scans and fetches, while actually running the queries obviously uses different plans?</p>