Read all docs via Native API


#1

I have two docs Customer and Journal within same database (Couchbase Lite).

What would be the best approach to read all Journal docs without reading the Customer doc?

Thanks.


#2

Here is a brief overview of how to query your data with map/reduce views in CBL. http://developer.couchbase.com/documentation/mobile/current/develop/guides/couchbase-lite/native-api/view/index.html


#3

The convention is to use a property named type with a string value that distinguishes the two, like "type":"customer" and "type":"journal".

You can then easily create views with map functions that only emit keys for docs of the appropriate type. The keys can be whatever you want to index — maybe the doc ID but maybe some other attribute. For instance the customer ID, if you want to sort by that or query ranges of them.


#4

Thank you all for the answers. It was very helpful.