7. Create a secondary index using a view with a map function

  1. From the database view in the Dashboard, click the Add (+) icon for Design Documents.
  2. Click New View.
  3. In the Design Document field, enter myview1 as the name.

  4. Edit the map function to check whether a document has a field called field2 and, if present, to return the document id and the value of that field.

  5. Click Save Document > Build Index to create the index.

    The view is immediately opened and shows a set of returned documents from the index.

    Note how the returned documents in the view have a key that is equal to the original document ID and a value corresponding to the value that was set in the field2 field. To copy the URL for this view, click API in the upper right and paste that into another browser tab to view the results.

    Here are the results in a browser: