How To Draw A Erd For Nosql Database
I love flexibility and freedom that JSON and document databases such as MongoDB bring. Nonetheless, when I'thou trying to figure out schema of the data by looking at JSON documents information technology can be actually painful.
Wouldn't a diagram like beneath be much better? Or at least a keen addition?
Well, what if I told you in that location is a tool that y'all tin build this results in a few minutes? Well, there is – Dataedo.
What you get
This tutorial volition teach you how you lot can:
- Discover schema of MongoDB documents,
- Document logical references,
- Build a diagram,
- Share a diagram as prototype
- Share entire database documentation in interactive HTML or PDF documents
You volition as well learn most:
- Different relationship types in MongoDB - embedded documents and references
Prepare the tool
1. Install
Showtime, you need to download and install Dataedo Desktop on your computer.
ii. Create repository/file
Next step is to create a repository. Repository is a file or database that volition hold all the metadata. Database is regular SQL Server or Azure SQL database. It is more than avant-garde option for multi user environments so if y'all can't get your hands on an example go with the file option. File is but a document you can salvage anywhere.
Now your set up is complete.
Connect to MongoDB and import Collections
Now that you have installed and configured Dataedo y'all can connect to your instance of MongoDB. To connect to database click Add in the ribbon and choose Database connectedness option.
Now choose MongoDB in the DBMS field:
And connexion type - Values or Connection cord.
How to find connection string?
If y'all don't have information technology you lot can ask your admin, developers or anyone who might know.
If you used MongoDB Compass to connect to your MongoDB case y'all will find information technology in Recents section. Click it, it will go copied into connectedness field. At present you can click edit to enable field. Copy it and paste into Dataedo.
Connect
When yous provide connection details and click Connect. Dataedo will connect to your MongoDB database and list collections. Yous can cull collections to import from this listing, but you just desire to skip this step with Side by side to import unabridged schema.
Schema Discovery
When you ostend, Dataedo will perform automatic schema discovery.
What happens here is that Dataedo:
- samples documents in collections, parses the JSON documents, and
- reads Schema Validation rules
and builds data lexicon from that information. When it finishes it creates complete data dictionary for your MongoDB database – list of collections and their attributes organized into hierarchy (documents, fields, arrays, etc.).
Discovering and Documenting Relationships
To create an ER diagram, you demand entities (collections) and relationships. Dataedo discovered entities and their fields. It is a bit more complicated (as always) with the relationships. MongoDB is non a relational database, it is a certificate store, then traditional ER modeling does not apply. However, we tin stretch the concept to fit JSON documents.
Let'south have an overview of relationships in this kind of databases.
Relationships in MongoDB
MongoDB, or whatsoever document store, has in full general ii categories of relationships – embedded documents and references.
- Embedded documents are nested in the data and tin be discovered and visualized automatically.
- References are logical, and equally such, cannot exist derived from data and needs to be documented manually in Dataedo. And this is where Dataedo shows its value – you end upward with additional data about data (metadata) that cannot be easily obtained by people working with data.
Discovering Embedded Documents Relationships
Embedded documents are specific to semi-structured data – power to embed some other record (document), or array of rows, into another record. It is defined directly in data and y'all can view those relationships in Dataedo right after schema import.
Embedded Document (Ane-to-Ane)
Basic embedded document is a i-to-one relationship. One parent record is related to ane child tape. In case below, (Hollywood) Studio has embedded i headquarters record.
Dataedo shows this relationship as a hierarchy of fields in collection entity. Parent object has a Document type.
On the diagram it is represented as a bureaucracy in the entity.
Embedded Array of Documents (One-to-Many)
More than complex design is the implementation of one-to-many relationship as embedded array of documents. In this case one parent record is related to multiple child tape. Example below shows ane Movie record having a list of histrion records.
As in the case of embedded document Dataedo shows such human relationship as hierarchy of fields, except in this case blazon of parent field is Document[] (array of documents) instead of Certificate.
On the diagram, just equally in the instance of embedded certificate, it is represented every bit a bureaucracy within an entity.
Documenting Reference Relationships
References are the aforementioned concept as in the case of relational databases – a data normalization technique where row in 1 set references row in another (or the same).
Document References (Many-to-Ane) - AKA Foreign Keys
Most typical reference in MongoDB document works exactly like strange keys in relational databases – field in one record (1) references record in another record (2). This chosen many-to-one relationship because field in tape 1 (director in movies collection) can reference exactly ane tape (person), while tape 2 (person) tin can be referenced by unlimited number of records (movies).
This reference is logical only, i.e. it is non defined with the data or collections construction. You need to know how data elements are related to each other, and then add this data into Dataedo metadata repository.
To ascertain human relationship (foreign key) with Dataedo, select the field that references other records, right click, and choose Add relation.
Now, in PK Table field choose a collection this field is referencing.
And in PK Cavalcade select primary key. Most likely that would exist _id cavalcade
Confirm with Save. Now a relationship has been saved in Dataedo metadata repository linking the ii collections. You can see this human relationship in References column adjacent to the field.
And in Relations tab as a dissever row.
On the diagram, it is represented as a regular relationship between entities.
Document References (Many-to-Many)
More advanced reference modeling technique in MongoDB is keeping references in an array, rather than simple field. In case below Studio certificate stores references to all its Movies in an array of integers.
Y'all document this relationship almost identically as the in the case of simple strange key.
But yous demand to point Many-to-Many cardinality past setting to Many in PK Cardinality field.
Information technology will be represented with a different icon.
On the diagram, information technology is represented as a many-to-many relationship between entities.
Creating a Diagram
So far, you have congenital a data dictionary and divers relationships. Now, it is time to build a diagram.
Create a module
To build a diagram you need to create a "module" that will be the container for the diagram. To create a module right click on Modules & ERDs and choose Add module/ERD. Provide a name for the module.
Create a diagram
Now you are fix to create a diagram. You can do it on the ERD tab of the module.
On the ERD tab there is a diagram pane and a toolbar with list of available collections/entities. Let'due south drag & drop to the pane entities you'd like to include in the diagram. Relationships should announced automatically. Yous tin cull which document fields y'all would like to testify by double clicking on entity and selecting columns you would like to be visible.
Yous can include data types in the diagram with Show column types in context menu.
This is the upshot – an Entity-Human relationship Diagram of documents in MongoDB:
Yous can echo that process multiple times creating multiple diagrams presenting dissimilar scope of the database.
Share diagram and documentation
Now that you have built the diagram, you should share it. After all, value of the diagram comes from looking at information technology, so you need to share it with broader community.
Share diagram equally prototype
You tin export diagram equally prototype to clipboard. To exercise it merely right click pane and choose Copy to clipboard. Now you can paste it in a certificate or save with MS Paint or any other graphical software.
Share entire documentation equally HTML
Much improve choice than just an prototype is to share the unabridged data dictionary and all diagrams in interactive HTML documentation. To export documentation, choose Export from the ribbon.
Then cull HTML Basic, then click Next on the post-obit pages and select the path and a proper noun on the Choose folder folio. Confirm with Export and your documentation volition be generated.
The result is this – interactive, searchable, lightweight HTML documentation.
Encounter live documentation sample
Share entire documentation in PDF
You can also export documentation to PDF certificate. Process is like exporting HTML, except in this case y'all cull PDF pick.
PDF includes ER Diagrams and data dictionary.
In that location you take it – a complete guide on how to build a diagram. Now it'due south time for you to create your first diagram for MongoDB.
Create your first diagram for MongoDB
[WEBINAR] From Schema Pattern to Schema Discovery in MongoDB
Scout a recording of Dataedo Practiced Webinar with MongoDB expert - Daniele Graziani, Consulting Engineer at MongoDB, and learn about the backward world of schema in MongoDB. Daniele volition share his experience from years of advising customers on implementation, transition to, and querying of their MongoDB databases.
Source: https://dataedo.com/tutorials/how-to-create-er-diagram-for-mongodb
Posted by: delacruzlinto1997.blogspot.com

0 Response to "How To Draw A Erd For Nosql Database"
Post a Comment