0
I need to perform a find on two Collections in mongodb using Aggregation and place the results in a single array.
I’m trying to do it this way, but it doesn’t work.
I have Visiting and Opportunities and I want to summarize the amount of records of each user. I have in both Collections the id_user variable that stores the id of the user who registered it.
Visita.aggregate([
{
"$match": {$and: [{Active: true}, {Root: true}]}
},
{
"$group": { _id: "$_idUser", totalVisita: { $sum:1} }
},
OpportunityEY.aggregate([
{
"$group": { _id: "$_idUser", totalOpp: { $sum:1} }
},
])
]).exec(function(err, result){
var managers = new Array();
for (var i = 0; i < result.length; i++) {
var manager = new Manager();
manager._id = (result[i]._id);
manager.totalVisit = result[i].totalVisita;
manager.totalOpp = result[i].totalOpp;
managers.push(manager);
However it only takes information relating to opportunity.
{_id: 1234567898765432345678, totalOpp: '2', totalVisita: "undefined"}