I have a webpage where users selects variables to filter and get database values. I tried passing the $match condition variables as below but i am not getting any results back
URL is : example.com?gender=M&date_from=20100101&date_to=201140101
I loop through the req.query to build the match condition string.
var matchQuery = [];
for (var param in req.query) {
qString = "{'" + param + "' : '" + req.query[param] + "'}";
matchQuery.push(qString);
}
var strmatchQuery = matchQuery.toString();
This outputs strmatchQuery as {'gender' : 'M'}, {'date_from' : '20100101'}, {'date_to' : '20140101'}
and then I call the mongodb aggregate function
dbmodel.aggregate( { $match: { $and: [ strmatchQuery ]} } , { $group : { _id : "$orderyear", totalorders : { $sum : 1 } } } )
But I dont get any results back. Any ideas?