title: Dynamically building MongoDB queries in NodeJS
body: <p>I receive a <code>POST</code> argument that looks like this:</p>
  
  <pre><code>sort:
      [ 
          { field: 'name', dir: 'asc', compare: '' },
          { field: 'org', dir: 'asc', compare: '' }
      ] 
  }
  </code></pre>
  
  <p>and I need to create a MongoDB query based on that, so it should look like:</p>
  
  <pre><code>db.collection("my_collection").find( ... ).sort({'name': 'asc', 'org': 'asc'}).toArray(...);
  </code></pre>
  
  <p>Anyways, keep in mind that more fields could be passed. Also, it could happen that none of those fields is passed, meaning that the query won't have <code>.sort()</code>.</p>
  
  <p>My question: How can I create dynamically a query with Node's MongoDB driver? Is there a query builder or something similar? </p>