title: NodeJS MongoDB Dynamic Query
body: <p>I have a NodeJS server running express with a get method at '/api/jobs/'. When called I get some querystring parameters from the url and they make a query against the MongoDB database to get jobs.</p>
  
  <pre><code>Example Url: '/api/jobs/?Groups=1,2&amp;Statuses=3,4'
  </code></pre>
  
  <p>The MongoDB query i am trying to construct is this:</p>
  
  <pre><code>{ $or: [{"Group.Id" : 1}, {"Group.Id" : 2}], $or: [{"Status.Id": 3}, {"Status.Id": 4}]}
  </code></pre>
  
  <p>If I run this directly against the database I get the results I need but I can't think of way of constructing the query dynamically in JavaScript. Any attempt i've made gives me an object like this as the $or property can only exist once in a proper JSON object.</p>
  
  <pre><code>{$or : [{"Group.Id" : 1}, {"Group.Id" : 2}]}
  </code></pre>
  
  <p>Any ideas on how to do this either using JavaScript or thorugh the MongoDB Node API?</p>