Help using aggregate with Report Widget

252 views
Skip to first unread message

eduardo...@dedalusprime.com.br

unread,
Mar 5, 2015, 7:03:20 AM3/5/15
to suppor...@runmyprocess.com
Our customer need some help on how to use the aggregate field (right syntax) of the Report Widget (like the attached file)

They have a field on the collection, "id_status_contrato", that has 4 values:

ANEXADO
NÃO ANEXADO
APROVADO
REPROVADO

and they would like to summarize by the contents of the field.

Which syntax would he use to do this?

Thanks,

Eduardo
--


------------------------------
Confidencialidade: A informação contida nesta mensagem de e-mail,incluindo
quaisquer anexos, é confidencial e está reservada apenas à pessoa ou
entidade para a qual foi endereçada. Se você não é o destinatário ou a
pessoa responsável por encaminhar esta mensagem ao destinatário, você está,
por meio desta, notificado que não deverá rever, retransmitir, imprimir,
copiar, usar ou distribuir esta mensagem de e-mail ou quaisquer anexos.
Caso você tenha recebido esta mensagem por engano, por favor, contate o
remetente imediatamente e apague esta mensagem de seu computador ou de
qualquer outro banco de dados. Muito obrigado.

aggregate.docx

Pray Desai

unread,
Mar 6, 2015, 3:15:59 PM3/6/15
to suppor...@runmyprocess.com, eduardo...@dedalusprime.com.br

(Copying response as answered on Support portal)

Hello Eduardo,

I assume you need to display a report widget that has two columns and four rows : first column is for status "id_status_contrato" and second column is showing its count in collection.

If this is the case, then make a report widget for this collection and configure just two columns (STATUS and TOTAL) as shown in attached screenshot.

Now, you need to write this script in Aggregation field as you had higlighted :

[{
"$group" : {
"_id" : {
"Status" : "$id_status_contrato"
},
"Total" : {
"$sum" : 1
}
}
}, {
"$project" : {
"STATUS" : "$_id.Status",
"TOTAL" : "$Total"
}
}
]



You can also refer to our doucmentation about aggregation in report here : http://docs.runmyprocess.com/Developer_Guide/Collection/Collection_JS_Freemarker#aggregation-in-a-report

In this documentation, it sums a collection field called "nb_of_cars" so in line 7 of JS, you see 
"Total" : {
"$sum" : "$nb_of_cars"
}

But if you donot want to sum a numeric field in collection, rather just want a count of the grouped field (like Status in your case) then you can write just 1 to increment the count everytime the grouped field is encountered so we had:

"Total" : {
"$sum" : 1
}


Let us know if this solves your issue.

Regards,
Pray Desai,
Fujitsu RunMyProcess.
collection-aggregated.png

eduardo...@dedalusprime.com.br

unread,
Mar 12, 2015, 2:45:55 PM3/12/15
to suppor...@runmyprocess.com
For future references, a great documentation about the subject at http://docs.mongodb.org/manual/reference/operator/aggregation-pipeline/.

Thanks Pray!

Eduardo
Reply all
Reply to author
Forward
0 new messages