Solution is simply emitting in map function of your view [trip, end_time]
. The CouchDB's rule for order of array keys is to sort it lexicographically. Example data set will be sorted like this:
{ end_time: 40, trip: "ABC", ... },
{ end_time: 10, trip: "BCA", ... },
{ end_time: 20, trip: "BCA", ... },
{ end_time: 30, trip: "CAB", ... },
...
If you want to have dates up to end_time
with customer with most recent end_time first, you may consider query parameter descending=true
as very useful (or emit [trip, -end_time]
what is even more useful if you need to have different order of fields in key array).