I am studying about NoSql, particularly, MongoDB. And I am going to build a simple blog site. However, I have a problem with mapping Entity-Realationship Diagram (ERD) to data model in MongoDB. It's Ok if I use SQL Database like MySQL but it's difficult with NoSql. Is there any tutorial about my problem? Thank for your answers!!!!
Sandeep Panda
co-founder, Hashnode
ERD is a way of mapping the relationships between different entities in your database. MongoDB is a document oriented and schema less database. This means there are no Tables and Joins.
You will still need ERD to know how exactly you are going to store data in your database, but things are little different here. In case of MongoDB you need to decide whether you are going to embed or refer. For instance, you are creating a blogging site. So, you are going to store posts and comments. In this case it's a good idea to embed
commentsdocument insidepostdocument. This is one of the benefits of MongoDB i.e. you can get all the data related to the post with a single query. As comments will always appear in the context of the posts it's almost always a good idea to embed comments in post. But what about the author of the post? In this case you need to store a reference to the actualuserinsidepostdocument.You can still use your ERD to keep track of how you are going to store data in MongoDB. But, in the end it comes down to - Embed or Refer?
More Info
Hope this helps!