title: Get one element from an array of objects that's part of one document (mongoose)
body: <p>I have a schema which contains <code>Friends</code> . Friends is an array where each element is an object that contains an id, gender, and emoji. </p>
  
  <pre><code>var userSchema = new Schema({
      id: {
          type: String,
          unique: true,
          required: true
      },
      gender: String,
  
      Friends: [{
          id: String
          gender: String
          emoji: String
  
      }]
  
  });
  </code></pre>
  
  <p>In the code below, I'm accessing one document which contains a Friends array and specifying that search with <code>distinct</code> such it only shows the document's array of Friends. I need to access only one element of that array that contains a specified id. Instead of filtering that array after the query like what's done in the code, is there a way to just get the element purely from the query? In other words, is there an extra functionality to distinct or some kind of mongoose operator that allows that? </p>
  
  <pre><code>User.findOne().distinct('Friends', { id: req.body.myId }).then(function(myDoc) {
  
      var friendAtt = myDoc.filter(function(obj) {
          return obj.id == req.body.id
      })[0]
  
  })
  </code></pre>