title: Order Mongoose/MongoDB query results by number of values not in an array
body: <p>I have two collections with the following simplified schemas:</p>
  
  <pre><code>// Ingredient 
  {
    _id: Number
  }
  
  // Recipe
  {
    _id: Number,
    ingredients: [{
      type: Number,
      ref: 'Ingredient'
    }]
  }
  </code></pre>
  
  <p>I'm trying to figure out how to implement a search query for recipes based on what ingredients you have available, sorted by the number of ingredients missing from each recipe.</p>
  
  <p>For example, if I have the following data:</p>
  
  <pre><code>// Ingredients
  {
    _id: 1
  },
  {
    _id: 2
  },
  {
    _id: 3
  },
  { 
    _id: 4
  },
  {
    _id: 5
  }
  
  // Recipes
  {
    _id: 1,
    ingredients: [1, 2, 5]
  },
  {
    _id: 2,
    ingredients: [2, 4]
  },
  {
    _id: 3,
    ingredients: [2, 3]
  }
  </code></pre>
  
  <p>and I input ingredients 2 and 3, the expected results would be</p>
  
  <pre><code>{
    _id: 3,
    ingredients: [2, 3] // Missing 0 ingredients
  },
  {
    _id: 2,
    ingredients: [2, 4] // Missing 1 ingredient
  },
  {
    _id: 1,
    ingredients: [1, 2, 5] // Missing 2 ingredients
  }
  </code></pre>
  
  <p>Is it possible to do this with a query alone?</p>