title: Get Distinct value using mongodb
body: <p>I am using one table that has user name and work duration of that user. The collection has multiple duration hours for the same user. I want to display the distinct user name and sum of duration hours for that user name.</p>
  
  <pre><code>db.collection.aggregate([       
      { "$match": { FacilityID: '59a53f0c6077b2a029c52b7f', ProjectID: '59c1171f734bcb3038e2bb67'} },
      { "$group": { _id: { TeamMemberUserID: "$TeamMemberUserID",Duration: "$Duration"}} },
      { "$project": { TeamMemberUserID: "$_id.TeamMemberUserID", _id: 0, Duration: "$_id.Duration", _id: 0} }
  ])
  </code></pre>
  
  <p>it is displaying username 3 times and showing </p>
  
  <pre><code>siva 40
  siva 40
  siva 40
  </code></pre>
  
  <p>for that user has different Duration for different kind of work like: 20 hours for designing, 10 hours for coding, 10 for Testing. </p>
  
  <p>but I want display the user with the sum of duration hours of all his work.</p>
  
  <pre><code>User Name:    Phase       duration
  Siva          Testing      10
  siva          Coding       10
  siva          Designing    20
  </code></pre>
  
  <p>Expecting output:</p>
  
  <pre><code>Siva 40
  </code></pre>
  
  <p>The above query executing username while grouping with duration hours. The duration hours is vary due to that it is displaying username according to the duration.</p>