From previous work on CouchDB 1.6.1, I know that it's possible to implement document joins in a couple ways:
For example, with a simple schema of 'studentsand 'courses
:
// Students table
| Student ID | Student Name
| XYZ1 | Zach
// Courses table
| Course ID | Student ID
| COURSE1 | XYZ1
This SQL query:
SELECT [Student Name], [Course ID] FROM Students RIGHT OUTER JOIN Courses ON Students.[Student ID] = Courses.[Student ID]
Could be implemented in CouchDB 1.6 with a map function:
// Map function
function(doc){
if (doc.type == 'Course') emit(doc["Student ID"], doc);
if (doc.type == 'Student') emit(doc["Student ID"], doc)
}
And either a group and reduce function
// Group would produce:
Student ID: [{course doc}, {student doc}, {course doc}, etc]
// Reduce would allow you to then process student and course docs for a single ID (with CouchDB protesting about expanding view indexes)
Or you could use a List function to iterate through either a grouped or ungrouped Map index.
Looking at documentation for Mango here, there is mention that _find (which I'm assuming is the 'Mango endpoint') uses indexes. I don't see way of saying 'where a field is equal to another field', but then I'm not very familiar with Mango at all...
Question:
- Can you 'emulate' document joins in Mango?
- If you can, would this be better or worse than using MapReduce to do the same thing?