title: Mongoose/mongodb - get only latest records per id
body: <p>I have an Inspection model in mongoose:</p>
  
  <pre><code>var InspectionSchema = new Schema({
      business_id: {
          type: String,
          required: true
      },
      score: {
          type: Number,
          min: 0,
          max: 100,
          required: true
      },
      date: {
          type: Number, // in format YYYYMMDD
          required: true
      },
      description: String,
      type: String
  });
  
  InspectionSchema.index({business_id: 1, date: 1}, {unique: true});
  </code></pre>
  
  <p>It is possible for there to be multiple inspections on the same Business (each Business is represented by a unique business_id). However, there is a limit of one inspection per business per day, which is why there is a unique index on business_id + date.</p>
  
  <p>I also created a static method on the Inspection object which, given a list of business_ids, retrieves all of the inspections for the underlying businesses.</p>
  
  <pre><code>InspectionSchema.statics.getAllForBusinessIds = function(ids, callback) {
      this.find({'business_id': {$in: ids}}, callback);
  };
  </code></pre>
  
  <p>This function fetches all of the inspections for the requested businesses. However, I want to also create a function that fetches <em>only the latest</em> inspection per business_id.</p>
  
  <pre><code>InspectionSchema.statics.getLatestForBusinessIds = function(ids, callback) {
      // query to get only the latest inspection per business_id in "ids"?
  };
  </code></pre>
  
  <p>How might I go about implementing this?</p>