All views within Couchbase operate as follows:
Views are updated when the document data is persisted to disk. There is a delay between creating or updating the document, and the document being updated within the view.
Documents that are stored with an expiry are not automatically removed until the background expiry process removes them from the database. This means that expired documents may still exist within the index.
Views are scoped within a design document, with each design document part of a single bucket. A view can only access the information within the corresponding bucket.
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).
Document IDs that are not UTF-8 encodable are automatically filtered and not included in any view. The filtered documents are logged so that they can be identified.
Views can only access documents defined within their corresponding bucket. You cannot access or aggregate data from multiple buckets within a given view.
Views are created as part of a design document, and each design document exists within the corresponding named bucket.
Each design document can have 0-n views.
Each bucket can contain 0-n design documents.
All the views within a single design document are updated when the update to a single view is triggered. For example, a design document with three views will update all three views simultaneously when just one of these views is updated.
Updates can be triggered in two ways:
At the point of access or query by using the
stale parameter (see
Section 9.2.4, “Index Updates and the
Automatically by Couchbase Server based on the number of updated documents, or the period since the last update.
Automatic updates can be controlled either globally, or individually on each design document. See Section 9.2.5, “Automated Index Updates”.
Views are updated incrementally. The first time the view is accessed, all the documents within the bucket are processed through the map/reduce functions. Each new access to the view only processes the documents that have been added, updated, or deleted, since the last time the view index was updated.
In practice this means that views are entirely incremental in nature. Updates to views are typically quick as they only update changed documents. You should try to ensure that views are updated, using either the built-in automatic update system, through client-side triggering, or explicit updates within your application framework.
Because of the incremental nature of the view update process, information is only ever appended to the index stored on disk. This helps ensure that the index is updated efficiently. Compaction (including auto-compaction) will optimize the index size on disk and optimize the index structure. An optimized index is more efficient to update and query. See Section 5.4, “Database and View Compaction”.
The entire view is recreated if the view definition has changed. Because this would have a detrimental effect on live data, only development views can be modified.
Views are organized by design document, and indexes are created according to the design document. Changing a single view in a design document with multiple views invalidates all the views (and stored indexes) within the design document, and all the corresponding views defined in that design document will need to be rebuilt. This will increase the I/O across the cluster while the index is rebuilt, in addition to the I/O required for any active production views.
You can choose to update the result set from a view before you
query it or after you query. Or you can choose to retrieve the
existing result set from a view when you query the view. In
this case the results are possibly out of date, or stale. For
more information, see
Section 9.2.4, “Index Updates and the
The views engine creates an index is for each design document; this index contains the results for all the views within that design document.
The index information stored on disk consists of the combination of both the key and value information defined within your view. The key and value data is stored in the index so that the information can be returned as quickly as possible, and so that views that include a reduce function can return the reduced information by extracting that data from the index.
Because the value and key information from the defined map function are stored in the index, the overall size of the index can be larger than the stored data if the emitted key/value information is larger than the original source document data.