i am mongodb beginner. Junior JavaScript developer using mongodb/mongoose
i wonder if anyone can help me for this easy challenge :i would like to group results based on dates ( i am able to group and able to filter by date but not both of them )
schema :
const ExpenseSchema = new Schema({
item: String,
amount: Number,
date: Date,
group: String,
})
enter code here
sample :
{
"_id": {
"$oid": "608c4fd352efae8cc8a10100"
},
"item": "Amril",
"amount": 435.42,
"date": {
"$date": "2018-05-05T11:06:00.000Z"
},
"group": "food",
"__v": 0
}
My NOT working mongoose query
enter code here
Expense.aggregate([
{
$match:
{
date: { $gt: startDate, $lt: endDate }
}
},
{
$group:
{
_id: '$group',
totalAmount: { $sum: "$amount" }
}
}], function (err, total) {
res.send(total)
})
thanks in advance