title: Get a list of all unique tags in mongodb
body: <p>I am beginning with mongodb and have a collection with documents that look like the following</p>
  
  <pre><code>{
      "type": 1,
      "tags": ["tag1", "tag2", "tag3"]
  }
  {
      "type": 2,
      "tags": ["tag2", "tag3"]
  }
  {
      "type": 3,
      "tags": ["tag1", "tag3"]
  }
  {
      "type": 1,
      "tags": ["tag1", "tag4"]
  }
  </code></pre>
  
  <p>With this, I want a <em>set</em> of all the tags for a particular type. For example, for type 1, I want the set of <code>tag1, tag2, tag3, tag4</code> (any order).</p>
  
  <p>All I could think of is to get the tags and add them to a <code>set</code> in python, but I wanted to know if there is a way to do it with mongodb's mapreduce or something else. Please advise.</p>