Functionality:
I have a Angular project for which I have to generate a graph showing invoiceDate vs saleAmount. The data is fetched from the invoice collection.
var invoiceRef = this.afs.collection<Invoice>('invoices',
ref=> ref.orderBy('creationDate','desc'));
Here I am getting the saleAmount and invoiceDate for each invoice.
Issue
How to count the saleAmount for each invoice Date?
In traditional SQL you would write something like
SELECT COUNT(saleAmount) FROM invoice GROUP BY invoiceDate;
How to do the same using angularfire queries for firestore?
Not sure it can be done directly from a firestore query, but you can implement a function that does this after you get the data (or before, with cloud functions).
It could look like this:
const groupedInovices = {};
invocies.forEach((inovice) => {
groupedInovices[invoice.date] = groupedInovices[invoice.date] ? groupedInovices[invoice.date]++ : 1;
});
You will end up with an object that looks like this:
{
"05/30/2019": 20
"05/29/2019: 13
}