I have documents, that look like
{
...
date: '2013-05-25T04:06:20.277Z',
user: 'user1'
...
}
I would need to find documents that have a date within a given range, and a given user. I also need to sort by date.
I have tried emit([doc.user, dateToArray(doc.date)], null)
but with this, I cannot sort by date, because AFAIK the key that needs to be sorted on has to be on the left side. Is this correct?
If I try to flip the keys the other way around, no matter what user I put in the startKey & endKey it does not change anything.
for example: startKey: [[0,11,21,0,0,0],"user1"]
, endKey: [[2016,11,21,0,0,0],"user1"]
finds documents from all users, even though I would suppose it to find only documents, where the second key is user1.
How should I do this? My document count can go up to millions, so doing stuff on code-side is out of question..