You are viewing the documentation for a prerelease version.

View Latest

Views for Non-JSON Objects

    Views on non_JSON data enable range queries on the key data.

    If the data stored within your buckets is not JSON formatted or JSON in nature, then the information is stored in the database as an attachment to a JSON document returned by the core database layer.

    This does not mean that you cannot create views on the information, but it does limit the information that you can output with your view to the information exposed by the document key used to store the information.

    At the most basic level, this means that you can still do range queries on the key information. For example:

    function(doc, meta)
        emit(, null);

    You can now perform range queries by using the emitted key data and an appropriate startkey and endkey value.

    If you use a structured format for your keys, for example using a prefix for the data type, or separators used to identify different elements, then your view function can output this information explicitly in the view. For example, if you use a key structure where the document ID is defined as a series of values that are colon separated:


    You can parse this information within the JavaScript map/reduce query to output each item individually. For example:

    function(doc, meta)
        values =':',3);
        emit([values[0], values[1], values[2]], null);

    The above function will output a view that consists of a key containing the object type, application name, and unique object ID. You can query the view to obtain all entries of a specific object type using:

    startkey=['monster', null, null]&endkey=['monster','\u0000' ,'\u0000']