Hi all, Hope somebody could help me with this topic... I have a mongoDB query based in Objects as "Ticket" structure, each ticket usually contains Tasks Object and each of them have an Owner, if the Ticket is Open, the associate Owner is “OpnPrps.CurAgtNme”, by other hand if the ticket is Closed, the associate Owner is “Nms.CloAgt”. This is how my database (JSON) looks: "result" : [ { "_id" : NumberLong(3131032306336), "TicId" : 1147552, "OrgId" : 729, "Sts" : "Closed", "CrtDat" : ISODate("2015-04-23T18:50:46.000Z"), "CloDat" : ISODate("2015-04-23T19:46:26.000Z"), "ShtDes" : "Copy of Employment agreement", "Des" : "EE wants a copy of employment agreement. address was verified.", "DesSum" : "EE wants a copy of employment agreement. address was verified.", "Sol" : "ISIGHT TICKET NUMBER:<br><h1>US-04-15-01109</h1>", "CrtAgtId" : 20444, "CloAgtId" : 20149, "CrtApp" : null, "IsInt" : false, "HasPrtTsk" : null, "PexBodId" : "", "PayGrp" : "", "RvwDat" : null, "RclDat" : null, "IsDynDueDatDef" : false, "OlaDat" : ISODate("2015-04-25T00:50:50.000Z"), "SlaDat" : ISODate("2015-04-25T00:50:50.000Z"), "DynDueDatElaDat" : null, "ReaTim" : "00:00:00", "LstUpd" : ISODate("2015-04-23T19:46:26.000Z"), "VrsOnl" : 2, "VrsArc" : 1, "OpnPrps" : null, "Nms" : { "Cmp" : "Organization1 US", "Org" : "Organization1", "Srv" : "Policies", "SrvGrp" : "17. Workforce Administration (NGR)", "Wkg" : "WORKGROUP1", "Pri" : "", "Tir" : "T1", "Src" : "Call", "CrtAgt" : "Arun ", "CloAgt" : "Felicia" }, "Olas" : { "_id" : 2, "EntNam" : "ENTITY", "DueDat" : ISODate("2015-04-25T00:50:50.000Z"), "AmbDat" : ISODate("2015-04-24T20:50:49.000Z"), "DueDatElaDat" : null, "AmbDatElaDat" : null, "SlaDuration" : 18, "TotTim" : NumberLong(0), "TotTimPndEnt" : NumberLong(0), "TotTimPndEmp" : NumberLong(0), "RclInSla" : false }, "Tsks" : { "_id" : 1, "Typ" : "Planned", "CrtDat" : ISODate("2015-04-23T18:50:46.000Z"), "CloDat" : null, "LstUpd" : ISODate("2015-04-23T18:50:46.000Z"), "DueDat" : ISODate("2015-04-25T00:50:50.000Z"), "TimCplTsk" : 1080, "DueDatEla" : false, "AgtOwnId" : null, "WkgSklId" : 45387, "EntId" : 2, "Sts" : "Open", "PrdTskId" : 201, "Ttl" : "Provide Navigational Assistance", "Des" : "Provide Navigational Assistance", "SrvSklId" : 45792, "PriSklId" : null, "TotTim" : 0, "PtnId" : null, "PtnTic" : null, "DepTskId" : null, "IsAct" : true, "IsMndOnCloTic" : false, "Nms" : { "AgtOwn" : null, "Wkg" : "CM_T1", "Ent" : "ENTITY", "SrvSkl" : "Policies", "PriSkl" : null, "Ptn" : null, "Frm" : "" }, "AscTicItm" : null, "FrmId" : null, "Flds" : [] }, And Query in mongodb looks like: db.tickets.aggregate([ {$match:{ 'Nms.Org': 'Organization1', 'Nms.Cmp':'Company', 'Nms.Wkg':'Workgroup’ }}, {$project:{ _id:0, 'Tsks._id':1, 'Tsks.Sts':1, 'Tsks.DueDat':1, 'Sts':1, 'Nms.Org':1, 'Nms.Cmp':1, 'Nms.Wkg':1, 'Nms.CloAgt':1, 'OpnPrps.CurAgtNme':1, 'OpnPrps.CurEntNme':1, 'Olas.EntNam':1 }}, {$unwind : "$Olas" }, {$unwind : "$Tsks" }, {$match:{$and:[{ 'Tsks.DueDat': {$ne: null}, 'Olas.EntNam': 'ENTITY', 'Tsks._id':{$gt:0} }]}}, {$group: {_id:{ Org:'$Nms.Org', Cmp:'$Nms.Cmp', Wkg:'$Nms.Wkg', DueDate:'$Tsks.DueDat', CurEntNme:'$Olas.EntNam', CurTskId: '$Tsks._id', DueDate:'$Tsks.DueDat', Owner1:'$OpnPrps.CurAgtNme', Owner2:'$Nms.CloAgt' }, All: {$sum: { $cond: [ { $eq: [ '$Tsks.DueDat' , null ] } ,0,1 ]}} }, } ]) With this query I’m able to get every ticket for every owner (even if they’re open or closed) and their associate tasks, my problem is that I want to group all the tickets withouth taking in consideration the status , something like a second group after the results I have now, see below: The table I get with jasper studio with this query looks like: Owner Inventory --------- -------------- Noemi 1 Owner1:Noemi | Owner2:null Carl 2 Owner1:null | Owner2:Carl Darla 2 Owner1:Darla| Owner2:null Carl 1 Owner1:Carl| Owner2:null Paola 2 Owner1:null| Owner2:Paola Noemi 2 Owner1:null | Owner2:Noemi As you can see, I’m getting repeated values due to the different field from each ticket. The table I'm looking for should be like this: Owner Inventory --------- -------------- Noemi 3 Owner1:Noemi | Owner2:Noemi Carl 3 Owner1:Carl | Owner2:Carl Darla 2 Owner1:Darla| Owner2:null Paola 2 Owner1:null| Owner2:Paola So, my problem is that I can’t found the way to group these results again to obtain the second table. Any ideas please? Thanks in advance. Kind regards.