Skip to content

Instantly share code, notes, and snippets.

@baphled
Created December 10, 2010 16:34
Show Gist options
  • Save baphled/736435 to your computer and use it in GitHub Desktop.
Save baphled/736435 to your computer and use it in GitHub Desktop.
I'm having problems trying to get my head around getting a collection of types along with number of times a skill is found in that doc type.
There are a number of document types that have a list of skills.
<pre><code>
{
"skills": "Windows, Network Admin, Linux",
"type": "Experience"
},
{
"skills": "Windows, Erlang, Linux",
"type": "Experience"
},
{
"skills": "Ruby, Rails, Erlang",
"type": "Project"
}
</code></pre>
I'm trying to get the number of times a skill is found in an document type.
The end result should look something like this:
<pre><code>
{
'type': Experience,
'skills': [
{'skill': 'Erlang', 'count': 1},
{'skill': 'Linux', 'count': 2},
{'skill': 'Network Admin', 'count': 1},
{'skill': 'Rails', 'count': 0},
{'skill': 'Ruby', 'count': 0},
{'skill': 'Windows', 'count': 2}
]
},
{
'type': Project,
'skills': [
{'skill': 'Erlang', 'count': 1},
{'skill': 'Linux', 'count': 0},
{'skill': 'Network Admin', 'count': 0},
{'skill': 'Rails', 'count': 1},
{'skill': 'Ruby', 'count': 1},
{'skill': 'Windows', 'count': 0}
]
}
</code></pre>
What would be the best way to do this?
@baphled
Copy link
Author

baphled commented Dec 11, 2010

I must admit my JS is crappy and my knowledge of couch is still in noob territory, the solution I have at the moment is not as clean as I'd like but it works for now.

Thanks a lot for the guidance and help, its much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment