How to represent a tree structure in NoSQL

Posted by Vlad Nicula on Programmers See other posts from Programmers or by Vlad Nicula
Published on 2014-05-24T10:00:35Z Indexed on 2014/05/26 22:00 UTC
Read the original article Hit count: 413

Filed under:
|
|
|

I'm new to NoSQL and have been playing around with a personal project on the MEAN stack (Mongo ExpressJs AngularJs NodeJs). I'm building a document editor of sorts that manages nodes of data. Each document is actually a tree.

I have a CRUD api for documents, to create new trees and a CRUD api for nodes in a given document.

Right now the documents are represented as a collection that holds everything, including nodes. The children parent relationship is done by ids. So the nodes are an map by id, and each node has references to what nodes are their children. I chose this "flat" approach because it is easier to get a node by id from a document.

Being used to having a relation table between nodes and documents, a relation table between nodes and children nodes I find it a bit weird that I have to save the entire "nodes" map each time I update a node.

Is there a better way to represent such a data type in NoSQL?

© Programmers or respective owner

Related posts about database-design

Related posts about node.js