incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohammad Prabowo <riz...@gmail.com>
Subject A few questions about View Collation and Linked Documents
Date Sat, 23 Jun 2012 06:47:34 GMT
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