operation: 100,
source: 'generator',
owner_id: ctx.from.id
})
.findOne({
operation: 100,
source: 'generator',
owner_id: ctx.from.id
}).sort({created_at: -1})
.aggregate([
{
"$match": {
operation: 100,
source: 'generator',
created_at: {$gt: new Date(Date.now() - 2 * 60 * 60 * 1000)}
}
},
{
"$project": {
"y": {"$year": "$created_at"},
"m": {"$month": "$created_at"},
"d": {"$dayOfMonth": "$created_at"},
"h": {"$hour": "$created_at"},
"value": 1
}
},
{
"$group": {
"_id": {"year": "$y", "month": "$m", "day": "$d", "hour": "$h"},
"total": {"$sum": "$value"}
}
},
{$sort: {_id: -1}},
{$limit: 1}
])
трудно угадать, но я бы начал с проверки трёх индексов: created_at, onwer_id и {operation:, source:}
Обсуждают сегодня