department {
"_id": "1",
"department": "Computers",
"type": "Department",
"room_no": "102",
"HOD": "Mr. G Rahul",
"floor": "1st Floor"
}
student {
"_id": "fdf370e2f43d4af1b505b8913502a5e4",
"_rev": "1-16df9a4cd45ca69009ab6c9767425a8e",
"student Name": "H Ravi",
"date_of_birth": "March 1, 1993",
"roll_no": "55",
"inter_marks": "820",
"secondary_marks": "420"
"department_id": "1",
"type": "student"
}
Map Function
function(doc) {
var id,department,student,hod,dob;
if(doc.type == 'student') {
id = doc.department_id;
dob = new Date(doc.date_of_birth)
student = doc;
}
}
emit(dob, {'_id': id,"student_doc": student});
}
写完map函数后,我们使用URL "//localhost:5984/db_name/_design/design_name/_view/view_name"调用view。在URL中,我们将添加?include_docs=true在"view_name"("//localhost:5984/db_name/_design/design_name/_view/view_name/?include_docs=true")之后通过在emit中使用_id获取文档,例如:emit(dob,{"_id": id})它将返回链接id的文档…我的问题是如何在reduce函数中访问文档
你不能,文档是在查询时获取的,而不是在索引时,所以reduce函数永远不会看到数据。对不起!