-
-
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? |
Cool, never knew about the _count call but it still yields essentially the same results though admittedly much nicer way :)
What the problem seems to be here is that I even though none of the Project docs have the Windows skill. I still need there to be an row that displays that a skill was not found in a specific doc type
{type: "Project", 'skill': 'Windows', 'count': 0}
.
I've come to the conclusion that I'd need a list for this, which would cross references the skills in an entry with the collective list of skills found. If the skill is not found then the count is set to zero.
hmm you may be better off ignoring skills with 0 count, and when you draw the ui, if the particular count is missing then you can assume 0
I managed to manipulate the data with some jQuery and two separate views but it still feels as though I could do this in a list view combination.
I'll experiment with this later in the week but it would definately be a lot better if I didn't have to rely on client-side code to manipulate the data further.
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
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.
just change the reduce to "_count"
the structure wont be an exact match but the data will be