title: MongoDB sorting by condition
body: <p>Hello guys i'm stuck in one condition where i need to sort the data that matches some conditions and then sort them by it's priority bases i.e
  first i want to sort the data via it's priority in descending order and then sort them if priority is 1 (high) sort the document via createdAt field else via it's date field.</p>
  
  <p>i currently create one aggregate by myself but it's not returning the correct data.</p>
  
  <pre><code>model.aggregate([
    {
      $match: {
        jobId,
        deprecated: false,
      },
    },
    {
      $project: {
        document: "$$ROOT",
        sort: {
          $cond: {
            if: {
              $eq: ["$priority", 1],
            },
            then: "$createdAt",
            else: "$date",
          },
        },
      },
    },
    {
      $sort: {
        priority: -1,
        sort: 1,
      },
    },
  ]);
  </code></pre>