Create compound keys for couchbase lite



I’ve watched a couple of the webinars on data modeling that talks about compound keys/ids for documents. From I’m able to ascertain, this can be accomplished on couchbase server. But I haven’t seen how it can be accomplished with couchbase lite.

I’m wondering if in absence of the ability to create compound keys in lite, that the operation should be performed on the server in conjunction with creating a new document, and then sync’d to couchbase lite.

I’ve also seen that documents have a “type” key that one can use to specify the type of document. Was wondering which should be used and for what purpose?

Can someone shed some light on this? Hope this posting makes sense.



Compound keys work fine in Couchbase Lite. The basic view and query architecture is the same as in Server (both inherited it from CouchDB.)

I gave a presentation last year that covered using compound keys; it should be relevant to your interests (:

I’ve also seen that documents have a “type” key

This is simply a data-modeling convention that a lot of apps use, not a hardwired property.


Hi Jens,

Just viewed your presentation. I really like the section on performance tips.

So is something like “u::1001::productsviewed” an example of a value for a key, which is used for creating views? Or can I or should I use that format for creating an id for a document?


Sorry, I don’t understand the question. You can use any JSON object as a key (well, except dictionaries, they don’t work well). It looks like you’re trying to combine several pieces of data in that key, so it would likely make more sense as a JSON array. But I don’t know what any of the stuff in that string means so I can’t give specific advice.


Hi Jens,

In the Spread video, at the 18:15 marker, Jakob shows an example of a document that has an id that uses a certain convention, “cd::p::-1s::01”, instead of a couchbase-generated UUID. This is something that I’m not familiar with, but I’m interested in using this format. It looks like this is something that is common in couchbase, but I haven’t seen examples of how to generate an id with that type of convention.


There’s nothing magic about that. To Couchbase the document ID is just an opaque string (the only thing it cares about is that it’s not allowed to start with an underscore.)

Some apps use formatting conventions in their document IDs so they can extract information from them, but that’s entirely up to the app and has nothing to do with CBL itself or with querying.