Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue ordering by date with mongoose
    primarykey
    data
    text
    <p>This is my Schema:</p> <pre><code>var userschema = new mongoose.Schema({ user: String, imagen: [{ name: String, author: String, date: { type: Date, default: Date.now }, }], follow: [String] }); </code></pre> <p>And this is the code:</p> <pre><code>usermodel.findOne({ user: req.session.user }, function (err, user){ usermodel.find({ _id: {$in: user.follow } }, function (err, images){ console.log(images); if (err) throw err; res.render('home.ejs', { user: user, following: images }); }); }); </code></pre> <p>The follow array in the Schema contains the <code>_id</code>s of the users that the actual user is following. I'm trying to get an output like this:</p> <pre><code>{ _id: 50fd9c7b8e6a9d087d000006, imagen: [ { name: 'fff.png', author: 'foo', _id: 50fd9ca2bc9f163e7d000006, date: Mon Jan 21 2013 20:53:06 GMT+0100 (CET) }, { name: 'mmm.png', author: 'foo', _id: 50fda83a3214babc88000005, date: Mon Jan 21 2013 21:41:34 GMT+0100 (CET) } ] }, { _id: 50fd9d3ce20da1dd7d000006, imagen: [ { name: 'ddd.jpg', author: 'faa', _id: 50fda815915e068387000005, date: Mon Jan 21 2013 21:42:57 GMT+0100 (CET) } ] } </code></pre> <p>And I'm trying to get an output similar at this, for example:</p> <pre><code> { [ { name: 'fff.png', author: 'foo', _id: 50fd9ca2bc9f163e7d000006, date: Mon Jan 21 2013 20:53:06 GMT+0100 (CET) }, { name: 'ddd.png', author: 'faa', _id: 50fda815915e068387000005, date: Mon Jan 21 2013 21:42:34 GMT+0100 (CET) }, { name: 'mmm.png', author: 'foo', _id: 50fda83a3214babc88000005, date: Mon Jan 21 2013 21:41:34 GMT+0100 (CET) } ] } </code></pre> <p>I think that what I want is imposible, or very complex, is there any solution for this...?</p> <p>Thank's advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload