couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <>
Subject Re: View Including Documents It Doesn't Seem Like It Should
Date Thu, 03 May 2012 16:10:11 GMT
Views are sorted by their full key and provide efficient lookup of a
single row or a single slice. When using startkey and endkey, couchdb
will return all rows equal to or greater than startkey that are also
less than endkey.

Array key ordering is defined as "compared element by element until
different. Longer arrays sort after their prefixes".

To achieve "What I want to be able to pull is all classes for a
specific course ID, ordered by learning method, but within a specific
date range." you will need to emit [doc.course_id, doc.date_range,
doc.learning_method] as your key, and use ?startkey=[course,
start_date]&endkey=[couch, end_date] to get the slice you are after.
The results will be in date order, not learning_method order.


On 3 May 2012 16:08, Matthew Woodward <> wrote:
> I'm sure Couch is doing exactly what it's supposed to so I'm really asking
> in order to understand why it's behaving this way.
> I'm working on a learning management system that has classes in it, and the
> class document has (among other things) a course ID (a course has multiple
> instances of classes associated with it), a learning method, and a
> date/time.
> For reference the learning method value will be one of either Classroom,
> Webinar, Videoconference, or Self-Paced, and my dates I'm formatting this
> way: "2012/05/01 08:00"
> I wrote a view that pulls classes with an array key including the course
> ID, the learning method, and the date:
> if (doc.type == 'class') { emit([doc.courseID, doc.learningMethod,
> doc.dtStart], null); }
> What I want to be able to pull is all classes for a specific course ID,
> ordered by learning method, but within a specific date range.
> When I use this start key, however, it pulls documents with a dtStart
> values outside the date range:
> ["courseidhere","A","2012/05/01 00:00"]
> In that case I'll get classes with a start date in April, for example. And
> just so it's clear, I'm using "A" as the start key for the learning option
> so I grab all the learning options.
> As I said my guess is I'm not quite understanding how the array keys work
> to the point where I get why given that start key it would pull documents
> with dates before what I have in my start key, so I'd appreciate any
> insight people might have.
> Thanks.
> --
> Matthew Woodward
> / Twitter: @mpwoodward
> Please do not send me proprietary file formats such as Word, PowerPoint,
> etc. as attachments.

View raw message