title: MongoDB: $in with an ObjectId array
body: <p>Just a quick question about something I've just experienced and I'm still thinking about why:</p>
  
  <pre><code>mongos&gt; db.tickets.count({ "idReferenceList" : { "$in" : [ { "$oid" : "53f1f09f2cdcc8f339e5efa2"} , { "$oid" : "5409ae2e2cdc31c5aa0ce0a5"}]}});
  </code></pre>
  
  <p>0</p>
  
  <pre><code>mongos&gt; db.tickets.count({ "idReferenceList" : { "$in" : [ ObjectId("53f1f09f2cdcc8f339e5efa2") , ObjectId("5409ae2e2cdc31c5aa0ce0a5")]}});
  </code></pre>
  
  <p>2</p>
  
  <p>I thought that both $oid and ObjectId spelling formats where exactly the same for MongoDB. Does anyone know why with the first query return 0 results and with the second one is returning 2 (the right answer)?</p>
  
  <p>Furthermore, I'm using Morphia framework which uses MongoDB Java driver to interact with MongoDB. I've realised that there exists a problem by searching with $in operator in ObjectIds arrays over fields that are not _id by executing this lines of code:</p>
  
  <pre><code>List&lt; ObjectId &gt; fParams = new ArrayList&lt; ObjectId &gt;();
  
  fParams.add(...);
  
  Query&lt;Ticket&gt; query = genericDAO.createQuery();
  
  query.field("idReferenceList").in(fParams);
  
  result = genericDAO.find(query).asList();
  </code></pre>
  
  <p>Thank you very much in advance.</p>
  
  <p>Regards,</p>
  
  <ul>
  <li>Luis Cappa</li>
  </ul>