Created
December 10, 2010 16:34
-
-
Save baphled/736435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
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
I don't understand how it's more code to that than adding a whole new _list piece.
however, if you use a list and are able to get it to directly output the HTML, that will be the fastest solution in the brower. But in production you'll need to run a squid or varnish in front of couch to hold the list runtime cost down