Duc,
have you seen this document
http://www.cmlenz.net/archives/2007/10/couchdb-joins
look for view collations
Also
What would be the harm in constructing a document with
{"ID":"someID","Name":"someName","Location":"someLocation","Serial":"someSerial","Model":"someModel","OS":"someOS","RAM":"someRAMsize","HD":"someHDsize"}
rather than the RDBMS format you describe (I assume that your data is
coming from a RDBMS).
I think that it would make your life easier.
best regards
cliff
On 11/11/10 16:35, Duc Phan wrote:
Hello all,
I am fairly new to couchDB and the Map/Reduce framework.
I am having problems creating a join view.
For example:
I have multiple documents in these two formats
First
------------------------------
-------------
Type : Inventory
ID: someID
Name: someName
Location: someLocation
Serial: someSerial
------------------------------------------
Second
-----------------------------------------
Type: Machine
Serial: someSerial
Model: someModel
OS: someOS
RAM: someRAMsize
HD: someHDsize
Here is what I am trying to do...
in SQL> Select ID, Name, Location, Type, Model, OS, RAM, HD from Inventory,
Machine where Inventory.Serial = Machine.Serial
That would join the two tables where the Serials match up.
How would I do that in couchDB where I have multiple documents with Type:
Inventory and Type: Machine
I would like the output to be something like:
{"ID":"someID","Name":"someName","Location":"someLocation","Serial":"someSerial","Model":"someModel","OS":"someOS","RAM":"someRAMsize","HD":"someHDsize"}
for all the machines
I have read couchDB the definitive guide and many blogs but I still haven't
found a way to solve my problem.
My attempt:
Map: function(doc){
if (doc.Type == "Inventory"){
emit ([doc.SERIAL,0],doc);}
else if (doc.Type == "Machine"){
emit([doc.SERIAL,1],doc);}
}
Reduce: ? What should I do here.
Thank you in advance for any suggestions or help.