I have about 5k in documents that I need to sort through and organize, pulling from mongodb, through express, and out to a ejs template. I have been able to get the documents to a ejs template successfully, but I'm having a tough time on how to tackle the second part of my project- Organizing the data.
Below is an example of how my data looks. My objective is to list all the defectlocations on the far left column (there about 30 in total), and count how many times defectlocation occur according to each year and month. I am not against using frameworks or jquery. The only thing I can think of is assigning a function to each cell which iterates over the array to see if it matches requirements for that cell. (but this seems like it goes against what programming is meant to be). Eventually, I would like to add graphs, but that seems really far-fetched at this point. One thing to add- this is not the only date range I will be using, they stretch as far back as 2012 up to 2017.
[{
"_id": "59cee5ce8ffdc0134854f0c1",
"repairorder": 7192822,
"month": 2,
"year": 2015,
"defectlocation": "MB"
}, {
"_id": "59cee5ce8ffdc0134854f0c2",
"repairorder": 7192822,
"month": 5,
"year": 2015,
"defectlocation": "COVER/HOUSING"
}, {
"_id": "59cee5ce8ffdc0134854f0c3",
"repairorder": 7192822,
"month": 2,
"year": 2015,
"defectlocation": "MB"
}, {
"_id": "59cee5ce8ffdc0134854f0c5",
"repairorder": 7192822,
"month": 3,
"year": 2015,
"defectlocation": "TOUCH PAD"
}, {
"_id": "59cee5ce8ffdc0134854f0c6",
"repairorder": 7192822,
"month": 4,
"year": 2015,
"defectlocation": "MB"
}]
Below is how I need it to display:
-----------------------------------------------------------------------
Defect Location | 01-2015 | 02-2015 | 03-2015 | 04-2015 | 05-2015 |
-----------------------------------------------------------------------
MB | | 2 | | 1 | |
-----------------------------------------------------------------------
Touch Pad | | | 1 | | |
-----------------------------------------------------------------------
Cover/ Housing | | | | | 1 |
-----------------------------------------------------------------------
TOTAL | | 2 | 1 | 1 | 1 |