title: How to pass mongodb match conditions from node.js URL parameters
body: <p>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</p>
  
  <p>URL is : example.com?gender=M&amp;date_from=20100101&amp;date_to=201140101</p>
  
  <p>I loop through the req.query to build the match condition string.</p>
  
  <pre><code>var matchQuery = [];
  for (var param in req.query) {
      qString = "{'" + param + "' : '" + req.query[param] + "'}";
      matchQuery.push(qString);              
  }
  var strmatchQuery = matchQuery.toString();
  </code></pre>
  
  <p>This outputs strmatchQuery as {'gender' :  'M'}, {'date_from' :  '20100101'}, {'date_to' :  '20140101'}</p>
  
  <p>and then I call the mongodb aggregate function </p>
  
  <pre><code>dbmodel.aggregate( { $match: { $and: [ strmatchQuery ]} } , { $group : { _id : "$orderyear", totalorders : { $sum : 1 } } } )
  </code></pre>
  
  <p>But I dont get any results back. Any ideas?</p>