couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohammad Prabowo <riz...@gmail.com>
Subject Re: A few questions about View Collation and Linked Documents
Date Tue, 26 Jun 2012 11:52:25 GMT
Hi Mathias,

I looked into your sample, and examined your views. But i think your way
doesn't work in my case, since my dept_emp id is just a monotonic number,
so i can't use substr() method

On Mon, Jun 25, 2012 at 1:26 PM, Mathias Leppich <mleppich@muhqu.de> wrote:

> Hi Mohammad,
>
> there is nothing wrong with the way how you want to store the data in
> couch, it might just become necessary to store data redundant to make
> bigger use of it inside the views.
>
> I took your example and put a little sample on my iris couch. see it here:
> http://muhqu.iriscouch.com/_utils/database.html?emp_dep/_all_docs
>
> There are 2 views:
> dep-emp: To see all employees of a given department:
>
> http://muhqu.iriscouch.com/_utils/database.html?emp_dep/_design/sample/_view/dep-emp
>
> http://muhqu.iriscouch.com/emp_dep/_design/sample/_view/dep-emp?include_docs=true&startkey=[%22dep/001%22]&endkey=[%22dep/001%22,[]]
>
> emp-dep: To see all departments a given employee is/was in:
>
> http://muhqu.iriscouch.com/_utils/database.html?emp_dep/_design/sample/_view/emp-dep
>
> http://muhqu.iriscouch.com/emp_dep/_design/sample/_view/emp-dep?include_docs=true&startkey=[%22emp/001%22]&endkey=[%22emp/001%22,[]]
>
>
> - mathias
>
> On Jun 23, 2012, at 8:47 , Mohammad Prabowo wrote:
>
> > I have a few questions about view collations and linked documents.
> Suppose
> > i have this schema:
> >
> > http://i.imgur.com/0xof6.png
> >
> > The red-bordered tables are what i'm interested in. I
> > have successfully convert it into document:
> >
> > {
> >        "id": "employees_n",
> > "emp_no": ..,
> > "birth_date": ..,
> > "first_name": ..,
> > "last_name" : ..,
> > "gender": ..,
> > "hire_date": ..,
> > "type" : "employees"
> > }
> >
> > {
> > "id": "dept_emp_n",
> > "emp_no": ..,
> > "dept_no": ..,
> > "from_date": ..,
> > "to_date" : ..,
> > "type" : "dept_emp"
> > }
> >
> > {
> > "id": departments_n,
> > "dept_no": ..,
> > "dept_name": ..,
> > "type" : "departments"
> > }
> >
> > Where n is ascending from 1 to count(*) of related tables
> > Questions:
> >
> > 1. I want to do view collations from doc.type = employees to doc.type =
> > departments. In SQL, i can easily JOIN these tables using something like
> >      "SELECT * FROM employees e JOIN dept_emp de ON e.emp_no = de.emp_no
> > JOIN departments d ON de.dept_no = d.dept_no"
> >
> >   Can i do this using view collations? I've been stuck after writting
> this
> > map function:
> >
> > function(doc) {
> > if (doc.type == 'employees') {
> > emit([doc.emp_no, 0], doc);
> > } else if (doc.type == 'dept_emp ') {
> > emit([doc.emp_no, 1, doc.dept_no], doc);
> >                } else if (doc.type == 'departments' ) {
> >                                        //What should i emit?
> >                                }
> > }
> >
> >
> > 2. I've been reading about linked documents, and it seems that it can
> only
> > be used with "_id" : some_id". Can i use another field like "dept_no" :
> > "some dept_no" so i can get all docs with that dept_no ?
>
>

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