couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Groves" <>
Subject Re: multiple keys and sorting
Date Mon, 17 Nov 2008 08:40:01 GMT
Hi Nicholas,

I just ran into the sort by date thing last night. My solution was:

function(doc) {
  time = doc.created_at.replace(/\D/g, "");
  emit([doc.document_id, time], doc)

to convert my time stamp (also in the form of a string like yours)
into a number which could be sorted.

Regarding pagination, see my blog post:



2008/11/17 Nicholas Retallack <>:
> 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?

View raw message