Get N latest distinct record from the collection [Mongodb]

Viewed 63
const eventSchema = new Schema({
  id: Schema.Types.ObjectId,
  serviceName: String,
  event: {
    type: { type: String, required: true },
    subType: { type: String, required: true },
  },
  properties: Object,
  created_at: { type: Date, default: Date.now() },
})

Above is the schema for Event Model. how can i get the latest N no of distinct record ( distinct by type & subType) with created_at date?

0 Answers
Related