couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicholas Retallack" <nickretall...@gmail.com>
Subject multiple keys and sorting
Date Mon, 17 Nov 2008 03:54:48 GMT
I ran into this problem today where I wanted to find documents by one
criteria but sort and paginate them by another.  I'll simplify my example to
make it easier to explain.

Lets say we have documents of the form {"dude":"joe", "date":"2008-11-11"},
and there are hundreds of them.  Now, lets say we have a set of dudes
["joe", "bob", "fred"] and we want to find all the documents among the three
of them.  That's easy enough in 3 queries.  But what if we want to sort by
date and paginate it?  Can't really do it.  So, how to work around it?

We could do 3 queries anyway, each with the maximum number of documents on
the page, then sort them ourselves and throw away the extras.  This gets
messy fast though, when you try to keep track of where to start the second
page in each query.

We could turn the relation around and make dude_groups a field in our
document, and have a view keyed by this and the date.  This works okay if
there is a fixed set of dude groups you'll be looking for.  However, if you
decide to change who's in one of the dude groups, you have a massive update
on your hands.

What would you guys suggest?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message