Mongoose filtering by array object property value

Mongoose filtering by array object property value



I am currently working on my exercise tracker project and one of issues I stumbled upon was filtering exercise values by exercise dates. Within my schema, i have defined property exercises that is holding the array of objects for exercises:

var userSchema = new mongoose.Schema({username: {type: String, unique: true} ,
                                     exercises: [{description: String,
                                                   duration: Number,
                                                   date: Date}]

So later when I filter the exercises I need to look inside the array exercises and return the objects meeting the conditions. The way I solved this was to return all exercise array of a particular user from model.findOne() searching by id and then filtering using Array.prototype.filter(). But this approach feels wrong to me because I have to load unnecessary data in memory.
Is there a way to filter out unnecessary exercise objects already during query to mongoose?