我的沙发数据库中有两种类型的文档(都在同一个数据库中),现在我创建了一个视图,它可以通过“_id”链接两个文档并使用沙发数据库视图 URL 返回数据。现在我想从地图函数中的两种类型中获取数据。文档类型和代码如下所示。
文件
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"
}
地图功能
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;
}
if(doc.type == 'department') {
if(doc._id == 'id') {
hod = doc.HOD;
department = doc;
}
}
emit([dob,hod], {'_id': id,"student_doc": student,"depart_doc":department});
}
第二个if条件没有在上述函数中执行。上面的代码只是地图功能。