In our project, we used hierarchical keys as follows: The first part of the key is something like the table name from the RDBMS: users - represents the "table"
Then each user has his own identifier in the example:
users:1 - "represents a single user"
We used ':' because I think it looks better than other delimiters. You can use any delimiter you like.
If you want to use sequential indexes, such as id in the previous example, you need to get them from some key, therefore:
users:counter - a key that contains the "last user id" (it acts as an auto-increment)
If you need to save some kind of βsubsectionβ for the user account, you can save it:
users:<user id>:subsection .
More complex example
users:1:avatars:1:url - means that with this key we get the URL of user 1 avatar, but if the user wants to store many avatars, they will be under users:1:avatars:X:url , where X will be value of users:1:avatars:counter .
We used this strategy for all documents that store only one value, JSON or even binary data.
So, just for your example, I will choose:
a:123-20140117:counter - this will mean that we have a (speaking in RDBMS language) table with the name "a", in table "a" we have an entry with id (or something else) "123-20140117 "with the cntrx field.
UPD: About the key size. It doesn't really matter. Yes, the keys are limited in size, but there are many ways to reduce it. One of them is to use hashes, but I think this is bad because the keys will be long and consume more memory. In our project, we used "short" keys for memcached bucket. We have an enumeration (which can also be stored in couchbase), which is the friendly name of a person and reduces its meaning.
Example: we have a set of records: a list of users with more than 30 photos. So, we have a key-value pair:
usersByPhotosCount - k:ubpc:{0}
and for 30 photos the key will be k:ubpc:30 .
But it is better to do such optimizations only in production. In development, it is better to have clear keys in the application and database (i.e. you can create two sets of kv pairs: normal for development, reduction and obfuscation for production and loading them depending on your environment).