barroco
barroco

Reputation: 3118

Query to get documents ordered by key1 ascending, and key2 descending using CouchDB

How I can get documents ordered by key1 (ascending) and key2 (descending) in a view?

Upvotes: 3

Views: 174

Answers (1)

Aldo Stracquadanio
Aldo Stracquadanio

Reputation: 6237

Very interesting question, the only answer I can think of is to write a map function that emits as key an array containing the asc key and the "opposite" of the desc key:

emit([doc.ascKey, opposite(doc.descKey)], doc);

The opposite function should iterate characters of the desc key to calculate the "alphabetical opposite" of them; for simplicity in ASCII it would be something like this pseudo-code snippet:

var oppositeStr = "";
for (char in str) {
  oppositeStr += chr(255 - char);
}

My solution is just speculative, but may also work! Maybe someone has a better idea?

Upvotes: 1

Related Questions