Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 19547 invoked from network); 13 Nov 2010 04:29:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Nov 2010 04:29:05 -0000 Received: (qmail 69373 invoked by uid 500); 13 Nov 2010 04:29:35 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 69194 invoked by uid 500); 13 Nov 2010 04:29:34 -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 69185 invoked by uid 99); 13 Nov 2010 04:29:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Nov 2010 04:29:34 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of anandology@gmail.com designates 209.85.161.52 as permitted sender) Received: from [209.85.161.52] (HELO mail-fx0-f52.google.com) (209.85.161.52) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Nov 2010 04:29:26 +0000 Received: by fxm15 with SMTP id 15so1571925fxm.11 for ; Fri, 12 Nov 2010 20:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=sGb0v14VbJa6Xvab+K0pqV8AvfDP2xcmxJ2PKc4WIjg=; b=K2HQ+oAnUzOUXJxVyvp/lXU529rBlSLyVWeH99xH9tdi1Malgcu1fG0dp532R+WNxq iVB1d+YkMu7PedpXA6GlhL2t522mQysYxZ95wozekEgVR1Z2iz/jnvRPS4xaNv1O/rcf RQNFWY5o7eKqcqGZnqo3hEZpYf8WS+MzMWupA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=gHCt0Yv/K+6v0+CXV7faWKVvyFhI6uBbUR+yTH+fftGYo/i+N9V5PYK+aGlGkoF8xD 4BfJoIFNqol9ChVslIL64xRHUkAuuiqRdpo4owfqURerf/0nsfUVGC8VXcvS9wh5hCmK TJv1h7wsix0ICKwGh90hA3rMq57qQY4I3lEgI= Received: by 10.223.72.197 with SMTP id n5mr2237453faj.8.1289622545727; Fri, 12 Nov 2010 20:29:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.147.199 with HTTP; Fri, 12 Nov 2010 20:28:45 -0800 (PST) In-Reply-To: References: From: Anand Chitipothu Date: Sat, 13 Nov 2010 09:58:45 +0530 Message-ID: Subject: Re: CouchDB model Problem To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 2010/11/12 Luis Carlos Junges : > Hi, > > I would like to use couchdb for a project but i am unsure how to model it= . > Basically i will have to store products and theirs respectives prices fro= m > several =A0stores. So, for a product product1, for example, i will have a > price p1 for store1, a price p2 for store 2 and so on...Considering that > those prices will be updated automatically, i was thinking in something l= ike > this: > > A document for the product with all information about it with id equal to > the product reference number > example: > > id:product1 > name: Product 1 > > > A document with the price and store id > id:89923848298398989d9fsd > revision:1 > store:45 > price:5.67 > refcode:product1 > updated: timestamp here > > > id:8992384829832938495298345 > revision:3 > store:46 > price:3.67 > refcode:product1 > updated: timestamp here > > > My idea is that each store will update their own prices. Now the problem = i > am no sure how to solve is that i can have multiple price documents with > differents ids (see example below) for the same store (a database > inconsistency). Could i use mapreduce to collect all the price documents = for > a specific product =A0and get only the latest one based on the time is > updated. If so, how can i do that? i mean, how would be the map and reduc= e > function? I would also like to delete the old ones. > > > > id:8992384829832938495298345 > revision:1 > store:46 > price:3.67 > refcode:product1 > updated timestamp here > > > id:92839198234 > revision:1 > store:46 > price:6.23 > refcode:product1 > updated timestamp here > > > I would appreciate any help How about using "$product-$store" as the _id for the document. In the above example, _id will be "product1-46". This will make sure that there are no duplicate price documents. Anand