title: Can i have a mongoose model that creates virtual attributes refer itself?
body: <p>I have a model that looks like this</p>
  <pre><code>    const studentSchema = new mongoose.Schema({
      student:{
          type: String,
          required: true
      },
      class:{
          type: String,
          required: true
      },
      familyId:{
          type: String,
          required: true
      }
  });
  
  studentSchema.virtual('familyMembers', {
      ref: 'Student',
      localField: 'familyId',
      foreignField: 'familyId',
  });
  
  const Employee = mongoose.model('Student', studentSchema);
  
  module.exports = Employee;
  </code></pre>
  <p>My question is can we create the virtual attributes for a collection that refers to itself?
  I did this because my expectation of this virtual attribute would be like:</p>
  <pre><code>{ 
      student: &quot;b&quot;, 
      class: &quot;2&quot;,
      familyId: &quot;family1&quot;
      familyMembers: [
       { 
         student: &quot;a&quot;, 
         class: &quot;1&quot;,
         familyId: &quot;family1&quot;
       },
       { 
         student: &quot;b&quot;, 
         class: &quot;2&quot;,
         familyId: &quot;family1&quot;
       },
       { 
         student: &quot;c&quot;, 
         class: &quot;3&quot;,
         familyId: &quot;family1&quot;
       },
     ]
  },
  </code></pre>