title: How to convert Mongo cli command to spring-data-mongo command for mongo aggreagtion using mongoTemplate
body: <p>I want to write the following query using mongo template.</p>
  <pre><code>db.collection.aggregate([
    {
      $project: {
        classes: {
          $map: {
            input: &quot;$classes&quot;,
            as: &quot;class&quot;,
            in: {
              classId: &quot;$$class.classId&quot;,
              students: {
                $filter: {
                  input: &quot;$students&quot;,
                  cond: { $in: [&quot;$$this._id&quot;, &quot;$$class.studentIds&quot;] }
                }
              }
            }
          }
        }
      }
    }
  ])
  
  </code></pre>
  <p>I have tried a lot but it is not working.</p>
  <pre><code>TypedAggregation&lt;OrderDocument&gt; aggregate = newAggregation(StudentDocument.class, 
                      match(Criteria.where(&quot;_id&quot;).is(id)),                    
                      project(&quot;classes&quot;)
                          .and(VariableOperators.Map
                                  .itemsOf(&quot;classes&quot;)
                                  .as(&quot;class&quot;)
                                  .andApply(doc-&gt; 
                                      new Document()
                                          .append(&quot;classId&quot;, &quot;$$class.classId&quot;)                                       
                                          .append(&quot;students&quot;, ArrayOperators.Filter
                                                  .filter(&quot;students&quot;)
                                                  .as(&quot;student&quot;)           
   .by(ComparisonOperators.Eq.valueOf(&quot;$$student._id&quot;).equalToValue(&quot;$$class.studentIds&quot;))))));
          
  </code></pre>
  <p>This is not giving the required response which is coming from the mongo shell command.</p>