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
9.9 View and Query Pattern Samples
Chapter Sections
Chapters

9.9.2. Validating Document Type

If your dataset includes documents that may be either JSON or binary, then you do not want to create a view that outputs individual fields for non-JSON documents. You can fix this by using a view that checks the metadata type field before outputting the JSON view information:

Javascript
function(doc,meta) { 
    if (meta.type == "json") { 
        emit(doc.firstname.toLowerCase(),null);
    }
}

In the above example, the emit() function will only be called on a valid JSON document. Non-JSON documents will be ignored and not included in the view output.