RavenDB map/reduce index for two levels deep nested relationship documents
<p>I have Job documents with the structure below.  These Job documents potentially have same crew members.  I'm trying to create a map/reduce index to compute the total number of unique crew members for a list of jobs, and I keep getting the total count instead of total unique count.</p>

<p>Here is the map/reduce index I've tried, which returned total count instead of unique count.  </p>

<pre><code>    Map = jobs =&gt; from job in jobs
                  from crew in job.Crews
                  from member in crew.Members
                  select new { UserID = member.UserName, Count = 1 }

    Reduce = results =&gt; from result in results.Distinct()
                        group result by 0 into g
                        select new { UserID = "", g.Sum(x =&gt; x.Count) }


{
    "Name": "Planetary Laser",
    "Crews": [
        {
            "Name": "Laser Team 1",
            "Members": [
                {
                    "UserName": "vader@empire.com",
                },
                {
                    "UserName": "uno@empire.com",
                },
                {
                    "UserName": "dos@empire.com",
                },
            ],
        },
        {
            "Name": "Laser Team 2",
            "Members": [
                {
                    "UserName": "emporer@empire.com",
                },
                {
                    "UserName": "bfett@empire.com",
                },
                {
                    "UserName": "dos@empire.com",
                }
            ],
        }
    ],
}
</code></pre>