Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 956749C1D for ; Thu, 3 May 2012 16:10:15 +0000 (UTC) Received: (qmail 81336 invoked by uid 500); 3 May 2012 16:10:14 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 81301 invoked by uid 500); 3 May 2012 16:10:14 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 81293 invoked by uid 99); 3 May 2012 16:10:13 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:10:13 +0000 Received: from localhost (HELO mail-yw0-f52.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:10:13 +0000 Received: by yhpp61 with SMTP id p61so2383201yhp.11 for ; Thu, 03 May 2012 09:10:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.179.38 with SMTP id dd6mr1119196igc.9.1336061411260; Thu, 03 May 2012 09:10:11 -0700 (PDT) Received: by 10.42.110.76 with HTTP; Thu, 3 May 2012 09:10:11 -0700 (PDT) In-Reply-To: References: Date: Thu, 3 May 2012 17:10:11 +0100 Message-ID: Subject: Re: View Including Documents It Doesn't Seem Like It Should From: Robert Newson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 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". https://wiki.apache.org/couchdb/View_collation 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. B. 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 > matt@mattwoodward.com > http://blog.mattwoodward.com > identi.ca / Twitter: @mpwoodward > > Please do not send me proprietary file formats such as Word, PowerPoint, > etc. as attachments. > http://www.gnu.org/philosophy/no-word-attachments.html