title: Aggregation Framework with mongoose and arrays
body: <p>I made a question related with this, but I have a new doubt with the Aggregation Framework with mongoose. For example, I have this schema:</p>
  
  <pre><code>var userschema = new mongoose.Schema({
  
     user: String,
     pass: String,
     following: [String],
     imagen: [{ 
  
                title: String,
                date: { type: Date, default: Date.now },
                name: String,
                author: String,
  
             }],
  
  
  });
  </code></pre>
  
  <p>And this is the code with the Aggregation Framework:</p>
  
  <pre><code>app.get('/home', middleware.yeses, function (req, res){
  
   usermodel.findOne({ user: req.session.user }, function (err, user){
  
   model.aggregate([
  
         {$match: { _id : '50f5c7265838530000000006' }},
         {$unwind: '$imagen'},          
         {$sort: {'imagen.date': 1}}
  
      ], function (err, imagenes){
  
          if (err) throw err;
  
          console.log(imagenes);
  
          res.send('foo');
  
      });
     });
    });
  </code></pre>
  
  <p>I'm trying to get in the console all the <code>images</code>, just the imagen schema like this for example:</p>
  
  <pre><code>{  title: 'footitle',
     name: 'foophoto.png',
     date: Tue Jan 1 2013 22:32:12 GMT+0100 (CET),
     author: 'foouser'  }
  </code></pre>
  
  <p>And get all the imagen schemas, ordered by date.</p>
  
  <p>The following array at the user's schema, contains the users' <code>_id</code>s that the actual user is following. So, with <code>{$match: { _id : '50f5c7265838530000000006' }},</code>, I get only the images of the users I'm following. The problem is that, when this code is execute, I receive this <code>[]</code>, the array of images that I get is empty, so the code doesn't work, because the users that I'm following have upload photos. </p>
  
  <p>When I delete this <code>{$match: { _id : '50f5c7265838530000000006' }}</code>, I get all the users, and their imagens, but I don't get only the imagen Schema, I get the whole user schema.</p>
  
  <p>So, what I want, is to get all the images, of the users that I'm following, ordered by date. Is there any solution for this? </p>
  
  <p>Thank's advance! </p>