couchdb-user mailing list archives

On Sun, Jun 21, 2009 at 10:15:31AM +0800, hhsuper wrote:
> but if i need to use the view as a datasource to the web page, i need change
> to right view to query on every sorting?
That's one way.
Another way is a single large view where you label each ordering of keys:
function(doc) {
emit(["by_foo", doc.foo||null, doc.bar||null, doc.baz||null]);
emit(["by_bar", doc.bar||null, doc.baz||null, doc.foo||null]);
emit(["by_baz", doc.baz||null, doc.foo||null, doc.bar||null]);
}
Then your client can query
startkey=["by_foo"]&endkey=["by_foo",{}]
where the by_foo can be chosen dynamically based on a parameter when
fetching the web page. This may or may not simplify your code, and this one
view might be larger than three separate views.
Brian.