title: Build mongoDB queries based on JSON from a user using Python
body: <p>I need a custom query builder for mongodb. I have already done user interface which the list of documents(fields) available for querying. A user can select "Result columns", "Conditions", "Group by" and "Sort by".
  Let me explain in using SQL language.. see the example:</p>
  
  <pre><code>SELECT col1, col2 FROM table WHERE col1=1 AND col2="foo" OR col3 &gt; "2012-01-01 00:00:00" OR col3 &lt; "2012-01-02 00:00:00" AND col5 IN (100, 101, 102) GROUP BY col4, col5 ORDER BY col1 DESC, col2 ASC
  </code></pre>
  
  <p>so </p>
  
  <ul>
  <li>SELECT col1, col2 -- result columns</li>
  <li>WHERE col1=1 AND col2="foo" OR col3 > "2012-01-01 00:00:00" OR col3 &lt; "2012-01-02 00:00:00" -- conditions</li>
  <li>GROUP BY col4, col5  -- group by statement</li>
  <li>ORDER BY col1 DESC, col2 ASC -- order by statement</li>
  </ul>
  
  <p>columns count, conditions, group by and order by should be generated by Python based on JSON data submitted by a used with user interface.</p>
  
  <p>I'm just curious is that possible to do for mongoDB with its MapReduce or not? May be you saw any modules for that?
  Also if you're good with MongoDB can you please translate this SQL query to MongoDB query?</p>