title: Finding a match inside an object of an array field, using mongoose
body: <p>I have this schema:</p>
  
  <pre><code>var eventSchema = new mongoose.Schema({
      name: String,
      tags: [{
          tagId: mongoose.Schema.Types.ObjectId,
          name: String,
          description: String
      }],
  });
  
  var Event = mongoose.model('Event', eventSchema);
  </code></pre>
  
  <p>And a array of tags ids, eg:</p>
  
  <pre><code>var arrayOfTagsIds = [23, 55, 71];
   // in this example I'm not using real mongo id's, which are strings
  </code></pre>
  
  <p>How can I use mongoose's find to search Events that have <strong>any</strong> of these tags?</p>
  
  <p>For example, this event should be in the results because it has tagId 23 and tagId 55:</p>
  
  <pre><code>{
     _id: ...,
     name: 'Football tournament',
     tags: [{ tagId: 23, name: 'football', description: '' },
           { tagId: 55, name: 'tournament', description: '' }]
  }
  </code></pre>
  
  <p>How must be the query inside find function?</p>
  
  <p>I was thinking of using: <code>tags.tagId: {$in: arrayOfTagsIds}</code> but I don't think that is going to work (it doesn't sound okay to use <code>tags.tagId</code>, because <code>tags</code> is an array)</p>
  
  <pre><code>Event
  .find({tags.tagId: {$in: arrayOfTagsIds}})
  .exec(function (err, events) { ... }
  </code></pre>
  
  <p>Also, doing this kind of query is too slow?</p>