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 DA0FB10B7D for ; Fri, 22 Nov 2013 14:38:59 +0000 (UTC) Received: (qmail 96314 invoked by uid 500); 22 Nov 2013 14:38:57 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 96280 invoked by uid 500); 22 Nov 2013 14:38:57 -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 96272 invoked by uid 99); 22 Nov 2013 14:38:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Nov 2013 14:38:57 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kevin.r.coombes@gmail.com designates 209.85.216.52 as permitted sender) Received: from [209.85.216.52] (HELO mail-qa0-f52.google.com) (209.85.216.52) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Nov 2013 14:38:49 +0000 Received: by mail-qa0-f52.google.com with SMTP id k4so3775165qaq.11 for ; Fri, 22 Nov 2013 06:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=YRUkybvgOKbILt2KsfVmOutN75INZ0FPfYkxjkbkcN8=; b=BkSSLcP2bIJu25dYEABJDWlHi8eOf9K3dzGL3Sa+viuP7ej2zdUH6PzhGH2f2gME5I kgMehioAZARb/ndH5mz/9TKFuQHQtIzauAMiUnvp68bz7plaruTT/phukRwk/HReymvz KZFLRNLBkk3s6o9AO1LtL3NXG/Ghn58xa9MXsX4g4DEnh4cDGSlSk+x7ZDApslu1eVb4 f4AqNjMkqpqdYriVP7n4atWSsuIXtY4DDFC61poQJOZcxE+pWfoVGXYfAqgRxuXA7dz7 eXQZkivD+E1IxcP9UB0zpy8zL2e7R/i+XjF/gAei6+DjFsxxsXG1Da5ISa3L7MBurLYy 3NXg== X-Received: by 10.229.223.194 with SMTP id il2mr22203996qcb.6.1385131108580; Fri, 22 Nov 2013 06:38:28 -0800 (PST) Received: from [10.34.93.58] (osu-wmc-public.osuwireless.ohio-state.edu. [140.254.70.33]) by mx.google.com with ESMTPSA id fc16sm5991208qeb.3.2013.11.22.06.38.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 06:38:28 -0800 (PST) Message-ID: <528F6C5B.6060308@gmail.com> Date: Fri, 22 Nov 2013 09:38:19 -0500 From: Kevin Coombes User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: couchdb data structure References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 11/22/2013 9:18 AM, John Norris wrote: > Hi Jens, > thanks for this - makes sense. > To continue on this path, so if I have separate document types, where > docTypeA has a reference to docTypeB, can I have a view that returns a > docTypeA based on a value within docTypeB object? My feeling from the > docs I have seen is "no". > Also, my view returns a list of key, values. And I can use the eg key > parameter to return a particular key, value. I can also use the keys > parameter to return more than one particular key. But can I return a > document based on more than one field. > What I mean is if a document type is defined as > { > id: xxxx, > fname: fred, > lname: smith, > dob: 01/01/2001 > } > The view can emit a key of "doc.fname, doc.lname" but can I search on > "fred" and "smith"? I could combine the two and search on "fredsmith" > I guess. You can define separate "lastname" and "firstname" views, and queries would look like http://yourcouch/yourdb/_design/q/_view/firstname?key="fred" or http://yourcouch/yourdb/_design/q/_view/latname?key="smith" If you are not sure if the first name is "fred" or "frederick", you can get them all with a query like http://yourcouch/yourdb/_design/q/_view/firstname?startkey="fred"&endkey="fredz" You could also define a view (say 'name') that looks like function(doc) { if(doc.fname) { emit(doc.fname, doc._id); emit(doc.lname, doc._id); emit(doc.fname+' '+doc.lname, doc._id); emit(doc.lname+', '+doc.fname, doc._id); } } and then you could search on first name, last name, or full name into the same view. > But, moving away from a name, it was two towns, then they could be any > order eg "london-leeds" or "leeds-london". Again, the could be > combined but can a doc be emitted twice eg emit called twice? Yes; see the above example. > Sorry this is all a bit confused, and the examples are not great but > hopefully the general question is getting over. > Regards, > John > >