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 2AB9C10022 for ; Sat, 16 Nov 2013 03:10:17 +0000 (UTC) Received: (qmail 5646 invoked by uid 500); 16 Nov 2013 03:10:12 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 5595 invoked by uid 500); 16 Nov 2013 03:10:10 -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 5529 invoked by uid 99); 16 Nov 2013 03:10:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Nov 2013 03:10:07 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of finelinestudio@gmail.com designates 209.85.214.181 as permitted sender) Received: from [209.85.214.181] (HELO mail-ob0-f181.google.com) (209.85.214.181) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Nov 2013 03:09:59 +0000 Received: by mail-ob0-f181.google.com with SMTP id uz6so4693161obc.26 for ; Fri, 15 Nov 2013 19:09:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=6QtyQD6MxyMPjQsJQYELmIOCw1vG0Lmu7jyJStYfxq4=; b=HZ3aZU6+lavutfO7j76Wp5b+pEOAj7bnihBnzhtNexf58NnLXHwuQtzTmpDQi74do/ o0rGvNrHM5GAGSFhpkVHRhHhKfF0qr2A2rL44vmTqDlLJlttvGB2NR7K5lgYvSnun6BX CqnpkWM8ZVlFrW2mz2bzwT3qS9yjIV0clrCooZu9TvskmFi2JgiIJdvuyTFaBUO/H9ML V/9vSSwOK9IR9AdQuCRz/wKPgfdHDz784kNB+k/DC3vzmyyY1CdlIo04dwFJyJe5T5Sv q185Z+sB4LwyP1/dEV6olMX9OH/JbhWLOu1mOKFrB4gefapDxzkDgdsdci21OOPux5bz +uBQ== MIME-Version: 1.0 X-Received: by 10.182.104.130 with SMTP id ge2mr9954727obb.6.1384571377824; Fri, 15 Nov 2013 19:09:37 -0800 (PST) Received: by 10.60.103.237 with HTTP; Fri, 15 Nov 2013 19:09:37 -0800 (PST) Date: Sat, 16 Nov 2013 14:09:37 +1100 Message-ID: Subject: Sort "join" view From: Tim Stewart To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=089e0112cf1024385504eb42a526 X-Virus-Checked: Checked by ClamAV on apache.org --089e0112cf1024385504eb42a526 Content-Type: text/plain; charset=ISO-8859-1 I'm learning about CouchDB, and wondering how I might solve the following problem. Given docs of two types (category and item) how would I produce a view grouping items with their category, ordered by name. It's that last bit about ordering by name that's stumping me. I can achieve the grouping, and indeed ordering of items by name within each category, as follows: function map(doc) { if (doc.type === "category") emit([doc._id, 0], doc); else if (doc.type === "item") emit ([doc.category_id, 1, doc.name], doc); } But the categories are sorted in ID order, not by name. I thought about using category name in its ID, so it would use that for sorting, but that would mean updating ID on the category and updating all its items every time the name changed. I thought about modelling the relationship differently with items nested within each category, but in this case an item can belong to multiple categories so it's not a good match. I thought about approaches based on filtered replication or combining views (is that even possible) but couldn't see a solution. Is there a simple thing I'm missing, or is the only solution to do this within the consuming app? Hoping to avoid that so I can use pagination etc. via the DB view. Thanks Tim --089e0112cf1024385504eb42a526--