title: Problems retrieving separate Document in Map-Function
body: <p>I've written a little function to get results based on two search terms a user can make. The terms are: <code>owner &amp; path</code> of a folder.</p>
  
  <p>The map function down below works so far that it gives me back the right folder when a user looks for <code>bob</code> &amp; <code>holiday</code>. 
  Unfortunately the <code>elfe if</code> part doesn't work, where I want to retrieve the files document. If I separate both <code>if</code>'s everything works. Why not in combination? :-)</p>
  
  <p><strong>Map-Function:</strong></p>
  
  <pre><code>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]});
        } 
    }
  }
  </code></pre>
  
  <p><strong>Documents:</strong></p>
  
  <pre><code>// Folder
  {
    "_id": "folder.abc",
    "name": "Holiday",
    "type": "folder",
    "owner": "bob",
    "path": "\\holiday",
    "files": [
      "file.123"
      ]
  }
  
  // Files
  {
    "_id": "file.123",
    "name": "Hawaii.jpg",
    "type": "file",
  }
  </code></pre>
  
  <p><strong>Search Query:</strong></p>
  
  <p><code>[Snip]?key=["bob","\\holiday"]&amp;include_docs=true</code></p>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>{
      "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"
                  ]
              }
          }
      ]
  }
  </code></pre>