How to retrieve hierrachical data in couchbase

I have some employee data which is in the format

  • Each employee has a manager
  • Manager is also an employee
  • Top level manager does not have a manager

So, my documents looks like




Here employee 123 has a manager 456 who in turn has a manager 789. Now i would like to know how to retrieve the data in couchbase if “i want to get all hierarchy of employee 123”. So, if my input is 123 then i need to get all the above 3 documents. In regular rdbms, we can write hierarchical/recursive queries to get this kind of data with a single query. how do we do this couchbase. I am using latest java sdk.

There are a couple of ways you could do this in Couchbase Server right now:

  • Look-up documents.
  • Views.

Here’s a blog post on look-up documents:

Here’s some info on views: