I'm trying to index bible verses creating a view in a design doc. The idea was to create keys that would allow lexicographic ordered search, concatenating book, chapter and verse number. For this to work, i'd need to pad zeros on chapter and verse number.
I've tried to use .padStart(2,'0') function, but the view created is empty.
a verse doc may look like this: {"_id":"007e0b09","_rev":"1-58c889c","ch":"05","vn":"16","verse":"bla bla bla"}
function (doc) {
if (doc.verse) {
//the function isn't rejected, but the resulting view is empty
var idx = doc.numBook+doc.ch.padStart(4,'0')+doc.vn.padStart(4,'0');
// if uncomented, a view is generated, but padded zeros are lost
//var idx = doc.numBook+doc.ch+doc.vn;m
emit(idx, doc._id);
}
return
}
Is there an alternate function better to use in couchdb design doc environment? Am i doing an error in the design of my index key? In this case, what should i do else? Is the design ok, but I should rewrite or import padStart some way? How? Thanks for reading.