title: Mongodb aggregation, how to combine or merge fields then count
body: <p>I have property(<code>home</code>) data in a collection. Each home can have multiple owners and is stored as separate fields for example <code>{home: 1, owner1: Fred, owner2: Jason, owner3: Stan}</code>  I want to get the list of top X owner names. Being new to mongodb I was able to adapt a basic example to aggregate and count one field (<code>owner1</code>) but I don't see how to combine the names from owner1, owner2, owner3 and then count.</p>
  
  <p>What I have now using pymongo</p>
  
  <pre><code>x = data2009.aggregate([
      { "$group": { "_id": "$OWNER1", "value": { "$sum": 1 } } },
      { "$sort": { "value": -1 } },
      { "$limit": 50 }
  ])
  </code></pre>
  
  <p>An example:
  DATA</p>
  
  <pre><code>{_id:1, home: 1, OWNER1: "Fred", OWNER2: "Stan", OWNER2: ""}
  {_id:2, home: 2, OWNER1: "Jason", OWNER2: "Fred", OWNER2: "Stan"}
  {_id:3, home: 3, OWNER1: "Fred", OWNER2: "Tim", OWNER2: "Stan"}
  {_id:4, home: 4, OWNER1: "Stan", OWNER2: "", OWNER2: ""}
  </code></pre>
  
  <p>Output would be</p>
  
  <pre><code>{
  {_id: Stan, value: 4}
  {_id: Fred, value: 3}
  {_id: Jason, value: 1}
  {_id: Tim, value: 1}
  }
  </code></pre>