Hi, Right, you can't get the two bits of information you want from the schema you have. If you go for a denormalised structure you can get it in a single request, without even using a view. It means you have to store more data, but you have everything in one place.
That said, making two requests isn't so bad. CouchDB is designed for lots of requests hitting it at once, again its about what resource you trade for what feature. Cheers Simon On Saturday, 23 June 2012 at 07:11, Mohammad Prabowo wrote: > Well, i thought that by using view collation, we can join those three > different schema. It seems that i must make two different GET request to > database: one for view collation between employees and salaries, and one to > lookup the dept_no by key... > > Thanks for the response! > > On Sat, Jun 23, 2012 at 6:01 PM, Simon Metson <[email protected] > (mailto:[email protected])> wrote: > > > Hi Mohammad, > > I think you need to rethink your document structure - doing a 1:1 port of > > a SQL schema is seldom a good idea, since so many of the underlying > > assumptions are different. > > It looks like you're trying to model an employees history as they move > > through departments, is that right? If so you could do that in a single > > document: > > > > { > > "id": "employees_n", > > "emp_no": .., > > "birth_date": .., > > "first_name": .., > > "last_name" : .., > > "gender": .., > > "hire_date": .., > > "dept" : [{"name": …, "start": … "end": …}, {"name": …, "start": … "end": > > …}] > > } > > > > > > Then use a view to pick out current dept. etc. > > Cheers > > Simon > > > > > > On Saturday, 23 June 2012 at 02: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 ? > > > > > > > > > >
