Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 17810 invoked from network); 22 Jun 2010 00:59:59 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Jun 2010 00:59:59 -0000 Received: (qmail 50150 invoked by uid 500); 22 Jun 2010 00:59:55 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 50086 invoked by uid 500); 22 Jun 2010 00:59:55 -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 Delivered-To: moderator for user@couchdb.apache.org Received: (qmail 14286 invoked by uid 99); 18 Jun 2010 16:54:57 -0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of francesco.mazzoli09@imperial.ac.uk designates 155.198.5.155 as permitted sender) MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 18 Jun 2010 17:54:27 +0100 Message-ID: Subject: Re: Next and previous element. From: Francesco Mazzoli To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-IC-MsgID: 1OPepn-0001ut-QX X-Virus-Checked: Checked by ClamAV on apache.org This is exactly what I was trying to do, but with sequential ids (I can't really use a timestamp since articles get accepted in groups, so they end up having the same timestamp) The problem is that I don't get the desired result. For example now I am using this view (slug_by_time): function(doc) { if (doc.type == 'Image' && doc.accepted) { emit(doc.id, {slug: doc.slug}); } } And, having one id, I am making request like: /troppotardi/_design/images/_view/slug_by_time?endkey=%2239f56554dba0e810d5a8d17225000f0f%22 to get the previous slugs and /troppotardi/_design/images/_view/slug_by_time?endkey=%2239f56554dba0e810d5a8d17225000f0f%22 to get the next one, but it doesn't work... -- Francesco On 18 June 2010 15:27, J Chris Anderson wrote: > > On Jun 18, 2010, at 5:31 AM, Francesco Mazzoli wrote: > >> This may be a simple question but I couldn't find a solution by myself. >> I am coding a web application with pylons (pylonshq.com) and couchdb, >> and I've stumbled upon a problem. >> It's a blog, and I assign a slug to every article. I get the slug from >> a get parameter in the address. >> I would like, from that article, to get the next and the previous one. >> I am using sequential uuids, and I've got this view slug_by_time that >> returns the docs slugs with the ids as keys. In this way they are >> ordered by time of creation. >> The problem is that, having one id, I can't get the previous and next >> element. My idea was simply to use the current id as startkey to find >> the next one end endkey to find the previous one, but I get weird >> results. > > if you store a timestamp on the item, you can have a view by timestamp and query with limit 1 on each side of the known timestamp for next and previous. > > Chris > >> >> Any suggestions? >> Thanks in advance, >> -- Francesco > >