title: How to get Couchdb/Cloudant design document ready for search all fields?
body: <p>I have a very simple database contains some data modals stored in Cloudant.</p>
  
  <pre><code>{
    "_id": "units_modal_the_oaks_preliminary",
    "_rev": "1-b541013bc008680b706ea01969dedb7a",
    "type": "units_modal",
    "label": "Preliminary Modal",
    "notes": "Notes here...",
    "project": "the_oaks",
    "data": [...]
  }
  </code></pre>
  
  <p>I connect Cloudant with PouchDB. My goal is simply make this database ready for query by all the fields except for data.</p>
  
  <p>I use PouchDB-Find to query the data. I've spent a whole day on the documentation for creating design document and views, but I could not figure out how to do it correctly. All document suggests that a map function &amp; a reduce function. I've tried various ways to manual design the map function, but when I run the query</p>
  
  <pre><code>remoteDb.find({
      selector:{type:"units_modal"}
  })
  </code></pre>
  
  <p>I got "no_usable_index" error. I can only use PouchDB-find's shipped method to create the index &amp; then I can get the results that I want:</p>
  
  <pre><code>remoteDb.createIndex({
      index: {
          fields: ['type', 'project','label','notes']
      }
  })
  </code></pre>
  
  <p>I looked at the design doc. Here's what I've got(I've renamed the id &amp; views):</p>
  
  <pre><code>{
    "_id": "_design/project",
    "_rev": "8-c7e2b7c0e1dbaff8e5641a4f06075e14",
    "language": "query",
    "views": {
      "units_modal": {
        "map": {
          "fields": {
            "type": "asc",
            "project": "asc",
            "label": "asc",
            "notes": "asc"
          }
        },
        "reduce": "_count",
        "options": {
          "def": {
            "fields": [
              "type",
              "project",
              "label",
              "notes"
            ]
          },
          "w": 2
        }
      }
    }
  }
  </code></pre>
  
  <p>All these are very confusing. It seams that there's nothing that I can find to explain the map except a map function. Where is the map function here? Where is the documentation &amp; explanation about map.fields, views.options.def and views.options.w?</p>
  
  <p>Could anybody suggest a simple way to design the views that can easily query all the fields about a certain type docs?</p>
  
  <p>Could anybody suggest a place that I can get more explanations about the map.fields, view.options &amp; all these little things about CouchDB?</p>
  
  <p>Is there a simple "if(type=='some type') indexAll();" solution?</p>
  
  <p>Many Thanks!</p>