title: MongoDB — How to sort lookup based on matching field?
body: <p>In my Mongo database, I have two collections — <code>speakers</code> and <code>speeches</code>, and I'm able to "join" them (getting a speaker's speeches) using the following code block:</p>
  
  <pre><code>// I've already found the 'speaker' in the database
  db.collection('speakers').aggregate([{
      $match: { "uuid": speaker.uuid } },
      { $lookup: {
          from: "speeches",
          localField: "uuid",
          foreignField: "speaker_id",
          as: "speeches" } }
  ]).toArray();
  </code></pre>
  
  <p>It works well, but I'd like to sort the speeches array by a <code>date</code> field or a <code>title</code> field, but nothing I do seems to make it happen. None of the examples I've seen here have done what I need them to do. I've tried adding <code>{ $sort: { "speech.title": -1 } }</code> after the <code>$lookup</code> block, but it did nothing. Is this even possible?</p>