title: How to convert this RDBMS schema to a MongoDB "schema" (and how to query against it)
body: <p>I am learning how to use MongoDB. It is taking me a while change my mindset from RDBMS/SQL to NoSQL.</p>
  
  <p>Using the following tables and queries as an example, I am hoping that someone can explain how I may implement this trivial RDBMS schema using mongrel, and how I can implement the queries using mongodb.</p>
  
  <pre><code>CREATE TABLE tag_category (id INT NOT NULL, name VARCHAR(32) );
  CREATE UNIQUE INDEX idxu_tag_cat ON tag_category(name);
  
  INSERT INTO tag_category(1, 'books');
  INSERT INTO tag_category(3, 'music');
  INSERT INTO tag_category(4, 'food');
  
  
  CREATE TABLE tag (id INT NOT NULL, 
                    categ_id INT REFERENCES tag_category(id),
                    tagval   VARCHAR(32) NOT NULL
                   );
  
  INSERT INTO tag (1,1,'romance');
  INSERT INTO tag (2,1,'scifi');
  INSERT INTO tag (3,1,'thriller');
  INSERT INTO tag (4,2,'rap');
  INSERT INTO tag (5,2,'country');
  INSERT INTO tag (6,2,'jazz');
  INSERT INTO tag (7,2,'classical');
  INSERT INTO tag (8,3,'Chinese');
  INSERT INTO tag (9,3,'Italian');
  INSERT INTO tag (10,3,'French');
  INSERT INTO tag (11,3,'South African');
  
  
  CREATE TABLE item (id INT,
                    entry_date DATE NOT NULL, 
                    name VARCHAR(32) );
  CREATE UNIQUE INDEX idxu_item ON item(name);
  
  INSERT INTO item (id, entry_date, name) VALUES(1, '2011-01-01', 'A love supreme');
  INSERT INTO item (id, entry_date, name) VALUES(2, '2011-01-01', 'A kind of blue');
  INSERT INTO item (id, entry_date, name) VALUES(3, '2011-02-01', 'Believe the hype');
  INSERT INTO item (id, entry_date, name) VALUES(4, '2011-01-01', 'Raising Hell');
  INSERT INTO item (id, entry_date, name) VALUES(5, '2011-01-01', 'The Chronic');
  INSERT INTO item (id, entry_date, name) VALUES(6, '2011-02-01', 'Blue Danube');
  INSERT INTO item (id, entry_date, name) VALUES(7, '2011-01-01', 'Schubert Sonata in B flat');
  INSERT INTO item (id, entry_date, name) VALUES(8, '2011-01-01', 'Also Sprach Zarathrustra' );
  -- ...
  
  CREATE TABLE item_tag (id INT, 
                         item_id INT REFERENCES tag(id),
                         name VARCHAR(32) );
  
  -- INSERT INTO item_tag (id, item_id, name) VALUES () ....
  </code></pre>
  
  <p><strong>QUERIES</strong></p>
  
  <p>For brevity sake, I will describe a single query, which (hopefully) encompasses most of the use case scenarios I expect to encounter. The query below is trivial to implement using SQL - with mongrel, I'm not too sure how to do it:</p>
  
  <ul>
  <li>FETCH all items tagged as EITHER RAP OR Classical (in music category) that have an entry date greater than '2011-01-01'</li>
  </ul>
  
  <p>To recap my question(s):</p>
  
  <ol>
  <li>How would I 'port' the schema above so it can be implemented in mongodb</li>
  <li>How would I request items as described in the query above, using the mongodb API?</li>
  </ol>
  
  <p>I am familiar with both Python and PHP - so a solution using either PHP or Python APIs would be great (although I am biased in favour of Python).</p>