many to many relationship in mongodb
===

I'm writing a small torrent indexer in Ruby ([here][1]) and would love to support MongoDB as an option for the database. Currently, I have the database set up with a many-to-many relationship between `tag`s and `torrent`s.

How would I format a query that gets all the `torrent_id`s from a map table that match to all the tags in a given list?

I did this in SQL like this:

`select torrent_id, count(*) num from tagmap where tag_id in (tag1, tag2, tag3, tag4) group by torrent_id having num = 4"`


  [1]: http://github.com/tekknolagi/indexer