title: Mongoosejs find on array of objectId
body: <p>I am struggling with this since few hours now and hence posting here. I am trying to use find() operator in mongoose, to find whether a key matches any single element in the array, similar to <a href="https://stackoverflow.com/questions/5818303/how-do-i-perform-this-query-in-mongoose-mongodb-for-node-js">How do I perform an id array query in Mongoose?</a> but not getting expected results.</p>
  
  <p>Here is my schema,</p>
  
  <pre><code>var a = new mongoose.Schema({
      b : { type : mongoose.Schema.ObjectId, ref: 'B' },
  });
  
  var A = mongoose.model('A', a);
  </code></pre>
  
  <p>now I have an array , arr[], which holds some possible object id's of class B. i.e </p>
  
  <pre><code>arr = ["54e545fb6a0d90bb0772808b", "xxxxxxxxxxxxx", ...]
  </code></pre>
  
  <p>I want to find all documents of type A, where the field b matches any of the elements in arr. Note that arr is an array of strings, but b holds ObjectId.</p>
  
  <p>So far I have tried, </p>
  
  <pre><code>A.find({b : {$in: arr}}, callback); //and
  A.find({b : {$in: new ObjectId("54e545fb6a0d90bb0772808b")}}, callback); //manually got this one value from db
  
  var callback = function (err, data) {
          console.log("----------------------");
          if (err)
              console.log(err);
          else {
              console.log(JSON.stringify(data, null, '\t'));
          }
          console.log("----------------------");
  
      }
  </code></pre>
  
  <p>Both of these does not seem to work. Thank you for the help.</p>