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"
]
}
}
]
}