Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 86241 invoked from network); 21 May 2009 23:58:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 May 2009 23:58:14 -0000 Received: (qmail 7343 invoked by uid 500); 21 May 2009 23:58:26 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7250 invoked by uid 500); 21 May 2009 23:58:26 -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 7240 invoked by uid 99); 21 May 2009 23:58:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2009 23:58:26 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of paul.joseph.davis@gmail.com designates 209.85.217.170 as permitted sender) Received: from [209.85.217.170] (HELO mail-gx0-f170.google.com) (209.85.217.170) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2009 23:58:18 +0000 Received: by gxk18 with SMTP id 18so2681973gxk.11 for ; Thu, 21 May 2009 16:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=ayHiEkGtKsXYja6wmzehMb5nPqW88fCEDxgs2zCwarw=; b=E93BgpgWLufPncBOLYimfaGqU+bM6ilMl0nI+00sU6Zi+plZUs+dwua4Otwj5VOkRQ 9b6ygf3ZCaM20v/bke5iiz39aq4ws6iFIxdCvcpt2fag/oHQMgNXrADafLD+GgOfqYqu BeMHzyk47d71QCFbFgU35ymibxQoYZlR6YESE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Z2FtuBJiszz0cK0LSzAM35eG8WSmXzuHF4rY5DwVBmtw9G1oT6i7oONR1TFPZjKYKP qhgO7XiEDdFZCe3n+5qFwOZteoyeEpZvq34LB8AysQsvNHu5f5r2512ckM2Swi5nzdUd syD8ssPt3d0/rrOX1S8PSdQ5J8JYkunc2bwIY= MIME-Version: 1.0 Received: by 10.100.46.10 with SMTP id t10mr6070894ant.116.1242950274917; Thu, 21 May 2009 16:57:54 -0700 (PDT) In-Reply-To: <6b6419750905211639u7888a6e6k5e9c166454819377@mail.gmail.com> References: <6b6419750905211639u7888a6e6k5e9c166454819377@mail.gmail.com> Date: Thu, 21 May 2009 19:57:54 -0400 Message-ID: Subject: Re: need help for a query From: Paul Davis To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org I don't think you can do that in 1 query because you have two unrelated orderings. Remember, don't be too concerned with multiple queries to the database. The layout I'd use is this: bar View: Map: emit(doc.user_id, doc.created_at) Reduce: return max(values); // You'll have to write max zing View 2: Map: emit([doc.user_id, doc.created_at], doc.post_id) Query strategy: Multi-get the bar view with your user id's of interest. top20 = [] For each user: get last 20 posts for user merge last 20 into top20 profit() There could be something more clever but nothing is coming right now. HTH, Paul Davis On Thu, May 21, 2009 at 7:39 PM, Patrick Aljord wrote: > Hey all, > > I have a blog with many posts and many comments done by many users, a > comment has a post_id, a user_id and a created_at holding the creation > date of the comment. > > I would like to query the 20 latest comments done only by user X, Y > and Z together, that is to say, if user X did the 20 latest comments > then it should return those 20 latest comments done by x only, but if > not, it should return for example something like 10 comments done by > X, 7 comments done by Y and 3 by Z, I hope you get the idea. And I > want them to be ordered by created_at. > > I don't think there is a way to do so with one query only. What would > be the best way to do this query with couchdb? > > Thanks in advance, > > Pat >