Am having the following Mongoose Schema in my Node Application
var expenseSchema = new Schema({
particular : String,
date : {type : Date, default: Date.now},
paid_by : String,
amount : Number,
month : String
});
var roomSchema = new Schema({
name: String,
admin: String,
roomies : [String],
expenses : [expenseSchema]
},{
collection : 'rooms'
});
I need to get expenses for a room for a particular month using find(). Here is what I was trying, however it returns me the whole room object
Room.findOne({_id : req.params._id, 'expenses.month' : 'oct'}).exec(function(err, result){
if(result == null) {
res.json({result : 'Oops! We couldn\'t find any rooms...'});
} else if(err) {
res.json({result : 'Error in getting Rooms'});
} else {
res.json({result : result});
}
});
Can someone help me with this?