I have a document with the following structure:
{
tags: ['bbb', 'aaa', 'ddd', 'ccc']
}
and I want to create a view which returns the hash of the sorted tags array as key. My approach is to sort the tags array and then calculate the hash of the sorted array.
The problem I am struggling with is how to sort the array inside a CouchDB view’s map function? It seems that the Array#sort() method does not work / is not available.
I can’t assume that the tags array is stored as a sorted array.
I figured it out. The problem was that I was trying to sort the tags array, but this is restricted in CouchDB because one cannot modify a documents property.
Therefore I had to ‘clone’ the array and then do a sort on the newly created one.
Where
views/lib/sha1is thesha1.jsfile provided with CouchDB.