I have a collection of "ofertas" in my DB and the data has this structure:
{
"_id" : ObjectId("6057a995e5a26c119d254f35"),
"empresa" : {
"direccion" : {
"direccion" : "concepcion arenal",
"cp" : "36950",
"provincia" : "pontevedra",
"poblacion" : "Moaña",
"pais" : "espana"
},
"nombre" : "caru sl"
},
"nombre_oferta" : "Offer Name",
"referencia_interna" : "111222",
"fecha_publicacion" : ISODate("2021-03-21T23:00:00.000Z"),
"fecha_caducidad" : ISODate("2021-04-19T22:00:00.000Z"),
"descripcion" : "Offer description",
"estado" : "caducada",
"pagada" : true,
"userId" : "XXX",
"candidatos" : [],
"createdAt" : ISODate("2021-03-21T20:16:21.438Z"),
"updatedAt" : ISODate("2021-04-20T22:08:14.221Z"),
"__v" : 0
}
And I have this MongoDB query:
[
{ $sortByCount: "$empresa.nombre" },
{$group: {
_id: 0,
empresas_ofertas:{$push: {
empresa:"$_id",
ofertas:"$count",
}},
}},
{ $unwind: "$empresas_ofertas"}
]
That groups the number of "ofertas", like this:
And I want to show data in MongoDB Atlas Charts as separated columns with the count of "ofertas" for each object of the "empresas_ofertas" array, but the chart just show one column with the total amount of "ofertas":
I changed the Y axis Aggregate from SUM to COUNT BY VALUE but it groups the data with the items that have the same amount of "ofertas". What I'm trying to do is to show all the objects in the "empresas_ofertas" array with the count of ofertas: first column should be 60 (IXAS Value SL), second columns should be 53 (caru sl)...
What am I doing wrong?