title: Getting only needed elements form array in MongoDb Schema
body: <p>I want to get only those element from notes Array that match the given <code>tag</code> from <code>tags</code> array in notes.</p>
  <p>For example <strong>:</strong> If I want to get only those notes from notes Array having <code>lrn</code> tag in tags array but I am getting either the whole object or only the first matching note.</p>
  <p>My Schema <strong>:</strong></p>
  <pre><code>const mongoose = require('mongoose');
  
  const noteSchema = new mongoose.Schema({
     user : {
         type: String,
         required: true,
         unique : true
     },
  
     notes : {
         type : [{
              title : {
                  type: String,
                  required: true
              },
              tags : {
                  type : [String],
                  required: true
              },
              note: {
                  type: String,
                  required: true
              }
          }],
         required: true
     }
  });
  
  const Notebook = mongoose.model('NOTEBOOK', noteSchema);
  module.exports = Notebook;
  
  </code></pre>
  <p>My sample data <strong>:</strong></p>
  <pre><code>{ _id: ObjectId(&quot;621c3a41fa2fe3c07f43edc9&quot;),
    user: '620c81434d8a65c1aa36e0d4',
    notes: 
     [ { title: 'Eraning',
         tags: [ 'ern', 'lrn', 'dik', 'pik', 'sik' ],
         note: 'Prior to his return, Craig worked at NeXT, followed by Apple, and then spent a decade at Ariba, an internet e-commerce pioneer where he held several roles including chief technology officer.\nPrior to his return, Craig worked at NeXT, followed by Apple, and then spent a decade at Ariba, an internet e-commerce pioneer where he held several roles including chief technology officer.\n',
         _id: ObjectId(&quot;62205a32bab7aed6315195e9&quot;) },
       { title: 'Lerningngs',
         tags: [ 'lrn', 'eat', 'drink' ],
         note: 'Prior to his return, Craig worked at NeXT, followed by Apple, and then spent a decade at Ariba, an internet e-commerce pioneer where he held several roles including chief technology officer.\n',
         _id: ObjectId(&quot;6220583cbab7aed63151958b&quot;) },
       { title: 'Learning',
         tags: [ 'learn', 'eran', 'buy', 'sell' ],
         note: 'Prior to his return, Craig worked at NeXT, followed by Apple, and then spent a decade at Ariba, an internet e-commerce pioneer where he held several roles including chief technology officer.Solving DSA from Maths.in and SolveMaths.org using great techniques by INDIA and RUSSIA.\n',
         _id: ObjectId(&quot;6220532dbab7aed631519531&quot;) },
       { title: 'Biology',
         tags: [ 'tissue', 'cell', 'myto', 'energy', 'glycogen', 'hydrogen' ],
         note: 'Prior to his return, Craig worked at NeXT, followed by Apple, and then spent a decade at Ariba, an internet e-commerce pioneer where he held several roles including chief technology officer.Solving DSA from Maths.in and SolveMaths.org using great techniques by INDIA and RUSSIA.\n\n',
         _id: ObjectId(&quot;621f88d4c189c6b5501c3d5f&quot;) },
       { title: 'Chemistry',
         tags: [ 'this', 'is', 'great', 'thing', 'to', 'do', 'by', 'time' ],
         note: '          Prior to his return, Craig worked at NeXT, followed by Apple, \n          and then spent a decade at Ariba, an internet e-commerce pioneer \n          where he held several roles including chief technology officer.\n',
         _id: ObjectId(&quot;621f85e9c189c6b5501c3d49&quot;) },
       { title: 'Physics',
         tags: 
          [ 'newtonlawsofmotion',
            'ktg',
            'thermo',
            'fluid',
            'mechanice',
            'bernaulii' ],
         note: 'P\' + hrg + 1/2rv^2 = constant',
         _id: ObjectId(&quot;621f8520c189c6b5501c3d3f&quot;) },
       { title: 'Maths',
         tags: [ 'trignometry', 'llp', 'continuity', 'tags', 'circle' ],
         note: 'Solving DSA from Maths.in and SolveMaths.org using great techniques by INDIA and RUSSIA.',
         _id: ObjectId(&quot;621f84d7c189c6b5501c3d37&quot;) },
       { title: 'DSA from Net',
         tags: [ 'dp', 'stack', 'queue', 'heaps', 'sorting' ],
         note: 'Solving DSA from Leetcode.in and GeeksforGeeks.org',
         _id: ObjectId(&quot;621c3a41fa2fe3c07f43edca&quot;) } ],
    __v: 7 }
  
  </code></pre>