Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 78205 invoked from network); 18 Nov 2008 13:29:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Nov 2008 13:29:10 -0000 Received: (qmail 16526 invoked by uid 500); 18 Nov 2008 13:29:16 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 16503 invoked by uid 500); 18 Nov 2008 13:29:16 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 16492 invoked by uid 99); 18 Nov 2008 13:29:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 05:29:16 -0800 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.221.10 as permitted sender) Received: from [209.85.221.10] (HELO mail-qy0-f10.google.com) (209.85.221.10) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 13:27:55 +0000 Received: by qyk3 with SMTP id 3so865433qyk.12 for ; Tue, 18 Nov 2008 05:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=GxfJxIgY9x550JwZCldH2TnzIF8evxzdPzoGWs7UFfw=; b=cG42uuUm9TBZf1F48NmA+D6iSFyLVQ23YvN3whIWvMfBhPxKNZ2gD6pNi8Z/9FZJV8 LieEuZRkuhoodm/v6hh7PU0AMSRTNA/9DXxEJBgnOHstLRTFaQYnEJgQ4HWTf+y3rzwB bJnyIBlpkvWMUwJ8xIuKTev9yDb1GVtXIf9tU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=fpT9LtpQTyiWT/9u7IHdjxrW1bYZp3180GBGFJUB+l1JzCEC4DVht+jMt8o42hqo+v RjKVjFR2G2qfnjWb6eIkwBKqk2sKL1FLT1EUWizeUArjyon7/CATY0p3cvwFuzDbPsmZ //hbHkPIbQi0UIz6fZ3I+cKUkPSGSNo6jd1l8= Received: by 10.214.78.5 with SMTP id a5mr3779146qab.245.1227014858623; Tue, 18 Nov 2008 05:27:38 -0800 (PST) Received: by 10.214.80.9 with HTTP; Tue, 18 Nov 2008 05:27:38 -0800 (PST) Message-ID: Date: Tue, 18 Nov 2008 08:27:38 -0500 From: "Paul Davis" To: couchdb-user@incubator.apache.org Subject: Re: View with incremental counter In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <226d73360811180437o18ddbaf7h6d3d025a886b4ce2@mail.gmail.com> <226d73360811180502t3bf0f20bjde280e3793c78e6c@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org Counters like this won't work. Your map function *must* return the exact same output for identical inputs. Imagine you generate the view once. Then edit a document. When it goes back through the map view your function would give it a new counter. Assuming your documents are edited in a non-deterministic order you won't be able to rely on the counter to mean anything. The only thing you could *almost* but not quite rely on it for would be to get the list of documents in the order of their last edit. And when I say almost, I mean it'll never work. But luckily there's _all_docs_by_seq which does exactly that. HTH, Paul On Tue, Nov 18, 2008 at 8:14 AM, Adam Groves wrote: > yeah but then my counter is still tied to the age of the document. Say > I'd like to return a list of documents sorted by name. > > I'd have a view like this: > > count = 0; > function(doc) { > if(doc.type == "document") { > count = count + 1 > emit(doc.name, count); > } > } > > I then create 4 documents in this order: Doc2, Doc3, Doc1, Doc4. > > The above view would give me the following results: > Key Value > ------------------- > Doc1 2 > Doc2 4 > Doc3 3 > Doc4 1 > > Which is not what I'm after. > > 2008/11/18 Ulises : >> That's what I thought. The output is definitely sorted by key, but the >>> document with a 'count' of one is in the middle of my results. >>> >>> I just tried this view for debugging: >>> >>> count = 0; >>> function(doc) { >>> if(doc.type == "document") { >>> count = count + 1 >>> emit(doc._id, [count, doc.updated_at]); >>> } >>> } >>> >>> and it turns out that the document with a count of 1 is the most >>> recently updated document. >>> >> >> But isn't the signature of the emit fn emit(key, value)? Wouldn't it make >> more sense then to emit([doc._id, count], some_value) however even then it'd >> end up sorted only by doc._id. Perhaps emit([count, doc._id], some_value) >> would do the trick. >> >> U >> >