I’m working with Nestjs graphql
let logs = await this.profileModel.aggregate([
{
$match: {
bindedBanque: name,
transactionDate: { $gte: startDate, $lt: endDate },
},
},
{
$lookup: {
from: 'tpes',
localField: 'nameUser',
foreignField: 'merchantName',
as: 'tpesBySite',
},
},
{
$lookup: {
from: 'logs',
localField: 'tpesBySite.terminalId',
foreignField: 'terminalId',
as: 'logsByTpes',
},
},
{ $unwind: '$tpesBySite' },
{ $unwind: '$logsByTpes' },
{
$project: {
// bindedSuperAdmin: '$bindedSuperAdmin',
// bindedBanque: '$bindedBanque',
// bindedClient: '$bindedClient',
snTpe: '$tpesBySite.sn',
terminalId: '$tpesBySite.terminalId',
transactionDate: '$logsByTpes.transactionDate',
transactionTime: '$logsByTpes.transactionTime',
outcome: '$logsByTpes.outcome',
},
},
{
$group: {
_id: { bank: '$logsByTpes.outcome' },
count: { $sum: 1 },
},
},
]);
console.log(logs);
return logs;
I checked the data type of the field was Date and the input was Date
By the way it worked with the function below
async getLogsByDate(startDate, endDate) {
let data = await this.logModel.aggregate([
{ $match: { transactionDate: { $gte: startDate, $lt: endDate } } },
{
$group: {
_id: { _id: '$outcome' },
count: { $sum: 1 },
},
},
]);
const computedValue = data.map((data) => {
return { name: data._id._id, value: data.count };
});
console.log('computedValue', computedValue);
return computedValue;
}
I really stuck any one could help me