Search:

Search all manuals
Search this manual
Manual
Couchbase Server Manual 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Developer Guide 2.0
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
6.5 Using the Views Editor
Chapter Sections
Chapters

6.5.1. Creating and Editing Views

You can create a new design document and/or view by clicking the Create Development View button within the Views section of the Web Console. If you are creating a new design document and view you will be prompted to supply both the design document and view name. To create or edit your documents using the REST API, see Section 9.7, “Design Document REST API”.

To create a new view as part of an existing design document, click the Add View button against the corresponding design document.

Note

View names must be specified using one or more UTF-8 characters. You cannot have a blank view name. View names cannot have leading or trailing whitespace characters (space, tab, newline, or carriage-return).

If you create a new view, or have selected a Development view, you can create and edit the map() and reduce() functions. Within a development view, the results shown for the view are executed either over a small subset of the full document set (which is quicker and places less load on the system), or the full data set.

Figure 6.24. Web Console — View Editing

Web Console — View Editing

The top portion of the interface provides navigation between the available design documents and views.

The Sample Document section allows you to view a random document from the database to help you write your view functions and so that you can compare the document content with the generated view output. Clicking the Preview a Random Document will randomly select a document from the database. Clicking Edit Document will take you to the Section 6.6, “Using the Document Editor”

Note

Documents stored in the database that are identified as Non-JSON may be displayed as binary, or text-encoded binary, within the UI.

Document metadata is displayed in a separate box on the right hand side of the associated document. This shows the metadata for the displayed document, as supplied to the map() as the second argument to the function. For more information on writing views and creating the map() and reduce() functions, see Section 9.5, “Writing Views”.

With the View Code section, you should enter the function that you want to use for the map() and reduce() portions of the view. The map function is required, the reduce function is optional. When creating a new view a basic map() function will be provided. You can modify this function to output the information in your view that you require.

Once you have edited your map() and reduce() functions, you must use the Save button to save the view definition.

The design document will be validated before it is created or updated in the system. The validation checks for valid Javascript and for the use of valid built-in reduce functions. Any validation failure is reported as an error.

You can also save the modified version of your view as a new view using the Save As... button.

The lower section of the window will show you the list of documents that would be generated by the view. You can use the Show Results to execute the view.

To execute a view and get a sample of the output generated by the view operation, click the Show Results button. This will create the index and show the view output within the table below. You can configure the different parameters by clicking the arrow next to Filter Results. This shows the view selection criteria, as seen in the figure below. For more information on querying and selecting information from a view, see Section 9.8, “Querying Views”.

Figure 6.25. Web Console — View Filters

Web Console — View Filters

Clicking on the Filter Results query string will open a new window containing the raw, JSON formatted, version of the View results. To access the view results using the REST API, see Section 9.8.1, “Querying Using the REST API”.

By default, Views during the development stage are executed only over a subset of the full document set. This is indicated by the Development Time Subset button. You can execute the view over the full document set by selecting Full Cluster Data Set. Because this executes the view in real-time on the data set, the time required to build the view may be considerable. Progress for building the view is shown at the top of the window.

Note

If you have edited either the map() or reduce() portions of your view definition, you must save the definition. The Show Results button will remain greyed out until the view definition has been saved.

You can also filter the results and the output using the in-built filter system that matches the options available to clients when using the view information.

For more information on the filter options, see Section 6.5.3, “Getting View Results”.