I have a collection where a field (chartStatus) is numeric, and I like to do a filter on that numeric field:
return Chart.find({"chartStatus": filterType}, {sort: {"demographics.lastName": 1}});
The problem arises when I forget to convert filterType to a numeric with parseInt.
For example, I’m using iron router, and taking a parameter from the url, like:
/myapp.com/getcharts/1
which would pass the 1 down to the find method but in this case, the “1” comes in as a string, and it doesn’t find any records.
This was tricky to debug, because doing console.log("filter coming in is " + filterType) shows the same output regardless of whether filterType is a string or a number.
Anyone have a suggestion on how to avoid this?