【发布时间】:2017-02-13 14:25:23
【问题描述】:
根据之前关于 CouchDB 1.6.1 的工作,我知道可以通过以下几种方式实现文档连接:
例如,使用简单架构 'studentsand 'courses:
// Students table
| Student ID | Student Name
| XYZ1 | Zach
// Courses table
| Course ID | Student ID
| COURSE1 | XYZ1
这个 SQL 查询:
SELECT [Student Name], [Course ID] FROM Students RIGHT OUTER JOIN Courses ON Students.[Student ID] = Courses.[Student ID]
可以在 CouchDB 1.6 中使用地图功能实现:
// Map function
function(doc){
if (doc.type == 'Course') emit(doc["Student ID"], doc);
if (doc.type == 'Student') emit(doc["Student ID"], doc)
}
还有一个 group 和 reduce 函数
// 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)
或者您可以使用 List 函数来遍历分组或未分组的 Map 索引。
查看 Mango here 的文档,提到 _find(我假设它是“Mango 端点”)使用索引。我不知道如何说'一个字段等于另一个字段',但是我对Mango一点也不熟悉......
问题:
- 你能在 Mango 中“模拟”文档连接吗?
- 如果可以,这会比使用 MapReduce 做同样的事情更好还是更差?
【问题讨论】:
标签: join mapreduce couchdb couchdb-2.0 couchdb-mango