Hi all, I would like to define modifierName
from email
variable and use it as a field in an aggregation query (specifically $group). How can I achieve that with this code?
let data = await Request.aggregate([
{ $match: searchFilters },
{ $lookup: {
from: 'user',
localField: 'user',
foreignField: '_id',
as: 'modifier',
} },
]);
let email = data.email; // julio@email.com
let modifierName = email.split('@')[0]; // julio
data = await Request.aggregate([
{ $match: searchFilters },
{ $lookup: {
from: 'user',
localField: 'user',
foreignField: '_id',
as: 'modifier',
} },
{ $group: {
_id: {
date: groupIdDate,
},
modifierName: { $sum: 1 }
} }
]);
Here is this question in a picture :
Any suggestion is appreciated, thank you!