I need to perform a find on two collections in mongodb using aggregation and put the results into a single array.
I'm trying to do this, but it does not work.
I have the collection Visits and Opportunities and want to summarize the amount of records of each user. I have in both collections the variable id_user that stores the id of the user that 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 about the opportunity.
{_id: 1234567898765432345678, totalOpp: '2', totalVisita: "undefined"}