title: How to MongoDB aggregation in Node.js
body: <pre><code>var mongoose = require('mongoose');
  var membersModel = require('./model_member.js');
  exports.request_friend_list = function(req, res){
  var userid=req.body.userid;
  console.log(userid);
  
  //  membersModel.find({_id: userid,friends:{status:0}},{_id:0,'friends':1,},function(err,data)
      membersModel.aggregate(
           {$match: {_id:userid}},
           {$project: {friends: 1}},
           {$unwind: "$friends"},
           {$match: {"friends.status": 0}}
       ,function(err,data){
       if(err){
          res.json({status:"error"});
          throw err;
      }else{
          if(JSON.stringify(data).length &gt; 0){
              console.log(JSON.stringify(data));
              res.json(data);
          }
          else{
              res.json({status: "Data is not Exist."});
              console.log("Data is not Exist.");
          }
      }   
  });
  </code></pre>
  
  <p><code>membersModel.find({...})</code> is operating normally, but <code>memberModel.Aggregation({...})</code> is not working. This also works in MongoDB:</p>
  
  <pre><code>db.members.aggregate({$match:_id: ObjectId("532b4729592f81596d000001"),$project:"friends":1,$unwind:"$friends",$match:"friends.status": 0})
  </code></pre>
  
  <p>What is the problem?</p>