7. Create a secondary index using a view with a map function
- From the database view in the Dashboard, click the Add (+) icon for Design Documents.
- Click New View.
- In the Design Document field, enter
myview1as the name.
- 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.
- 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: