title: Dynamic MongoDB queries
body: <p>I'm pretty new to NoSQL databases and I'm trying to figure out how to programmatically build MongoDB API queries. I'm using Angular 2 for my frontend and Node.js for my backend. </p>
  
  <p>I have users filtering songs and I want them to be able to filter them by multiple genres, I have 9 different genres.</p>
  
  <p>My base query is: </p>
  
  <pre><code>{"order": "created DESC"}
  </code></pre>
  
  <p>Then, for example - If they select hipHop and pop I want to make a function that will build this query. They can only add genres, so it would just be a matter of adding more or less genres inside the and brackets. </p>
  
  <pre><code>{"where": {
       "and": [
            {"genres.house": {"exists": "true"}},
            {"genres.pop": {"exists": "true"}}
       ]
     },
     "order": "created DESC"
  }
  </code></pre>
  
  <p>I'm using mLab for the DB and loopback to build my API. Not sure if that matters. </p>
  
  <p>Thank you!</p>