couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Duc Phan <th4ngn...@gmail.com>
Subject Re: Join Query View
Date Thu, 11 Nov 2010 19:02:15 GMT
Hi,
Thanks for your response.
I tried the js you sent and I got an error: reduce_overflow_error

regards,
Duc

On Thu, Nov 11, 2010 at 1:49 PM, Diogo Silva <manifesto@manifesto.blog.br>wrote:

> I guess if you just want to "merge" the docs of same key (serial) you can
> have a map like:
>
> function(doc){
> emit(doc.SERIAL,doc);
> }
>
> and reduce it with:
>
> function(key, values) {
> var obj = {};
> for(var i in values) {
> for(var k in values[i]) {
> obj[k] = values[i][k];
> }
> }
> return obj;
> }
>
>
> 2010/11/11 Duc Phan <th4ngnh0c@gmail.com>
>
> > Hello Cliff,
> >
> > First, thank you for your response.
> > I have seen that document (
> > http://www.cmlenz.net/archives/2007/10/couchdb-joins ) and almost every
> > single thing that returned from Google with the query of "Join+ View+
> Query
> > +CouchDB".
> > Please excuse my ignorant of these topics.
> > I have tried the view collations, by using this code:
> > function(doc){
> > if (doc.Type == "Inventory"){
> > emit ([doc.SERIAL,0],doc);}
> > else if (doc.Type == "Machine"){
> > emit([doc.SERIAL,1],doc);}
> > }
> >
> >
> > And when I run the view I get two rows for each machine (one contains
> info
> > in Inventory Doc and the other contains info in Machine Doc).
> > Is that my solution? There isn't a way to get the info from Inventory and
> > Machine on one row?
> >
> > And.. yes I did migrate the data from an Oracle DB. I can construct a
> > document like :
> >
> >
> {"ID":"someID","Name":"someName","Location":"someLocation","Serial":"someSerial","Model":"someModel","OS":"someOS","RAM":"someRAMsize","HD":"someHDsize"}
> >
> > but, I would like to know how to join them anyways because I will have to
> > do
> > many more join queries because many of those fields are related to other
> > documents.
> > I didn't think it was a good idea to put hundreds of fields into one
> > document.
> >
> > Again, thank you for your suggestions. Any other suggestions or tips
> would
> > be greatly appreciated since I have spent two days trying to solve my
> > problems.
> >
> >
> >
> > On Thu, Nov 11, 2010 at 12:17 PM, Cliff Williams <cliffywills@aol.com
> > >wrote:
> >
> > > 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.
> > >>
> > >>
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message