-1
I have a code that returns me arrays with the parameters I need to feed my HTML page, however, I need to include some conditions in this search so that it only takes the values after a certain date.
var obj = await Hist.aggregate([{$group: {
_id:'$pagform',
contagem:{$sum:1},
soma:{$sum:'$valor'}
}}])
labels = []
contagem = []
soma=[]
obj.forEach(x => {
labels.push(x._id),
contagem.push(x.contagem)
soma.push(x.soma)
});
res.json({labels, contagem, soma})
It would be code similar to find(), but return me a json with the same arrays as the query using Aggregate, for example:
var all = await Hist.find({hora_saida:{ $gt: '2020-02-01' }},{'pagform':1,'valor':1,'':1})
Very good your answer, helped too, thank you!!!
– Jean Júnior