0
我已经编写了一个基于用户可以制作的两个搜索词获取结果的小函数。条款是:文件夹的owner & path
。在地图功能中检索单独文档的问题
下面的地图功能向下工作到目前为止,当用户查找bob
& holiday
时,它会返回正确的文件夹。 不幸的是,elfe if
部分不起作用,我想在其中检索文件文档。如果我将两个if
分开,那么所有的东西都可以工作。为什么不组合? :-)
地图-功能:
function(doc) {
if (doc.type == 'folder') {
emit([doc.owner, doc.path], null);
} else if (doc.files) {
for (var i in doc.files) {
emit(doc.owner, {_id: doc.files[i]});
}
}
}
文件:
// Folder
{
"_id": "folder.abc",
"name": "Holiday",
"type": "folder",
"owner": "bob",
"path": "\\holiday",
"files": [
"file.123"
]
}
// Files
{
"_id": "file.123",
"name": "Hawaii.jpg",
"type": "file",
}
搜索查询:
[Snip]?key=["bob","\\holiday"]&include_docs=true
结果:
{
"total_rows":4,
"offset":2,
"rows":[
{
"id":"folder.abc",
"key":[
"bob",
"\\holiday"
],
"value":null,
"doc":{
"_id":"folder.abc",
"name":"Holiday",
"type":"folder",
"owner":"bob",
"path":"\\holiday",
"files":[
"file.123"
]
}
}
]
}