I am struggling in creating a design document key to enable flexible queries (involving multiple conditions in AND or OR) of a complex database stored with CouchDB 3.3.2.
After reading related documentations and previous posts on this topic, I realized that it may not be even possible to query a view using more than one condition.
For example, if I let my design document to emit a concatenated key with multiple fields like
emit([
('0000' + age).slice(-5),
('000' + gender).slice(-4),
('000' + sessionlist.length).slice(-4),
('000' + modalitylist.length).slice(-4),
('000' + tasklist.length).slice(-4),
('000' + runlist.length).slice(-4),
subj.substring(4)], null
);
I would get keys like ["08300","000M","0001","0001","0001","0000","045"] with the order matching age*100, gender, and length of certain search fields.
With this index, I can search the range of the first field (age) with startkey=["02000",{}]/endkey=["08000",{}], but I as long as I want to use other fields in AND to further filter the data, I could not - because couchdb's index left-side key takes higher priority than the keys on the right, I can only determine the left-sided keys first and allow only one key to filter the data.
I can also use a different index strategy - by emitting multiple keys
emit([('A000' + age).slice(-5),1]);
emit([('G00' + gender).slice(-4),2]);
emit([('S00' + sessionlist.length).slice(-4),3]);
emit([('M00' + modalitylist.length).slice(-4),4]);
emit([('T00' + tasklist.length).slice(-4),5]);
emit([('R00' + runlist.length).slice(-4),6]);
however, the problem with this is still that I can only use one index to filter the data.
I see a number of posts suggesting to create different design documents one for each search key, but again, when use startkey/endkey to query each design document, it can only handle a single condition, not a joint condition.
is it even possible to use views to filter data with multiple keys in CouchDB? I am really confused.