Organising information in hierarchies is something programmers have to deal with from time to time. Examples are:
Using a NoSQL document database (or SQL for that matter), it is quite easy to create a structure to organise this type of information; for each record/document/node, you simply need a reference to the parent (except for the top node).
So what's the problem?
The main problem is that querying and retrieving the whole or parts of the hierarchy will require complex code with recursion and an unknown number of queries which can put a big load on our database. Ouch!
In this blog post we will walk through a simple solution which lets you retrieve any (or all) parts of a hierarchy (a threaded discussion) using only ONE efficient database query in restdb.io. To follow along, you can just create a new restdb database yourself. Everything is done online, you only need a modern browser.