Cara menggunakan geojson mongodb

I love flexibility and freedom that JSON and document databases such as MongoDB bring. However, when I’m trying to figure out schema of the data by looking at JSON documents it can be really painful.

Cara menggunakan geojson mongodb

Wouldn’t a diagram like below be much better? Or at least a great addition?

Cara menggunakan geojson mongodb

Well, what if I told you there is a tool that you can build this results in a few minutes? Well, there is – Dataedo.

What you get

This tutorial will teach you how you can:

  1. Discover schema of MongoDB documents,
  2. Document logical references,
  3. Build a diagram,
  4. Share a diagram as image
  5. Share entire database documentation in interactive HTML or PDF documents

You will also learn about:

  1. Different relationship types in MongoDB - embedded documents and references

Prepare the tool

1. Install

First, you need to download and install Dataedo Desktop on your computer.

2. Create repository/file

Next step is to create a repository. Repository is a file or database that will hold all the metadata. Database is regular SQL Server or Azure SQL database. It is more advanced option for multi user environments so if you can’t get your hands on an instance go with the file option. File is just a document you can save anywhere.

Cara menggunakan geojson mongodb

Now your set up is complete.

Connect to MongoDB and import Collections

Now that you have installed and configured Dataedo you can connect to your instance of MongoDB. To connect to database click Add in the ribbon and choose Database connection option.

Cara menggunakan geojson mongodb

Now choose MongoDB in the DBMS field:

Cara menggunakan geojson mongodb

And connection type - Values or Connection string.

Cara menggunakan geojson mongodb

Cara menggunakan geojson mongodb

How to find connection string?

If you don’t have it you can ask your admin, developers or anyone who might know.

If you used MongoDB Compass to connect to your MongoDB instance you will find it in Recents section. Click it, it will get copied into connection field. Now you can click edit to enable field. Copy it and paste into Dataedo.

Cara menggunakan geojson mongodb

Connect

When you provide connection details and click Connect. Dataedo will connect to your MongoDB database and list collections. You can choose collections to import from this list, but you just want to skip this step with Next to import entire schema.

Cara menggunakan geojson mongodb

Schema Discovery

When you confirm, Dataedo will perform automatic schema discovery.

Cara menggunakan geojson mongodb

What happens here is that Dataedo:

  1. samples documents in collections, parses the JSON documents, and
  2. reads Schema Validation rules

and builds data dictionary 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.).

Cara menggunakan geojson mongodb

Discovering and Documenting Relationships

To create an ER diagram, you need entities (collections) and relationships. Dataedo discovered entities and their fields. It is a bit more complicated (as always) with the relationships. MongoDB is not a relational database, it is a document store, so traditional ER modeling does not apply. However, we can stretch the concept to fit JSON documents.

Let’s have an overview of relationships in this kind of databases.

Relationships in MongoDB


MongoDB, or any document store, has in general two categories of relationships – embedded documents and references.

  1. Embedded documents are nested in the data and can be discovered and visualized automatically.
  2. References are logical, and as such, cannot be derived from data and needs to be documented manually in Dataedo. And this is where Dataedo shows its value – you end up with additional information 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 – ability to embed another record (document), or array of rows, into another record. It is defined directly in data and you can view those relationships in Dataedo right after schema import.

Embedded Document (One-to-One)

Basic embedded document is a one-to-one relationship. One parent record is related to one child record. In case below, (Hollywood) Studio has embedded one headquarters record.

Cara menggunakan geojson mongodb

Dataedo shows this relationship as a hierarchy of fields in collection entity. Parent object has a Document type.

Cara menggunakan geojson mongodb

On the diagram it is represented as a hierarchy in the entity.

Cara menggunakan geojson mongodb

Embedded Array of Documents (One-to-Many)

More 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 record. Example below shows one Movie record having a list of actor records.

Cara menggunakan geojson mongodb

As in the case of embedded document Dataedo shows such relationship as hierarchy of fields, except in this case type of parent field is Document[] (array of documents) instead of Document.

Cara menggunakan geojson mongodb

On the diagram, just as in the case of embedded document, it is represented as a hierarchy within an entity.

Cara menggunakan geojson mongodb

Documenting Reference Relationships

References are the same concept as in the case of relational databases – a data normalization technique where row in one set references row in another (or the same).

Document References (Many-to-One) - AKA Foreign Keys

Most typical reference in MongoDB document works exactly like foreign keys in relational databases – field in one record (1) references record in another record (2). This called many-to-one relationship because field in record 1 (director in movies collection) can reference exactly one record (person), while record 2 (person) can be referenced by unlimited number of records (movies).

Cara menggunakan geojson mongodb

This reference is logical only, i.e. it is not defined with the data or collections structure. You need to know how data elements are related to each other, and then add this information into Dataedo metadata repository.

To define relationship (foreign key) with Dataedo, select the field that references other records, right click, and choose Add relation.

Cara menggunakan geojson mongodb

Now, in PK Table field choose a collection this field is referencing.

Cara menggunakan geojson mongodb

And in PK Column select primary key. Most likely that would be _id column

Cara menggunakan geojson mongodb

Confirm with Save. Now a relationship has been saved in Dataedo metadata repository linking the two collections. You can see this relationship in References column next to the field.

Cara menggunakan geojson mongodb

And in Relations tab as a separate row.

Cara menggunakan geojson mongodb

On the diagram, it is represented as a regular relationship between entities.

Cara menggunakan geojson mongodb

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 document stores references to all its Movies in an array of integers.

Cara menggunakan geojson mongodb

You document this relationship almost identically as the in the case of simple foreign key.

Cara menggunakan geojson mongodb

But you need to indicate Many-to-Many cardinality by setting to Many in PK Cardinality field.

Cara menggunakan geojson mongodb

It will be represented with a different icon.

Cara menggunakan geojson mongodb

On the diagram, it is represented as a many-to-many relationship between entities.

Cara menggunakan geojson mongodb

Creating a Diagram

So far, you have built a data dictionary and defined 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.

Cara menggunakan geojson mongodb

Create a diagram

Now you are ready to create a diagram. You can do it on the ERD tab of the module.

Cara menggunakan geojson mongodb

On the ERD tab there is a diagram pane and a toolbar with list of available collections/entities. Let’s drag & drop to the pane entities you’d like to include in the diagram. Relationships should appear automatically. You can choose which document fields you would like to show by double clicking on entity and selecting columns you would like to be visible.

Cara menggunakan geojson mongodb

You can include data types in the diagram with Show column types in context menu.

This is the result – an Entity-Relationship Diagram of documents in MongoDB:

Cara menggunakan geojson mongodb

You can repeat that process multiple times creating multiple diagrams presenting different 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 it, so you need to share it with broader community.

Share diagram as image

You can export diagram as image to clipboard. To do it simply right click pane and choose Copy to clipboard. Now you can paste it in a document or save with MS Paint or any other graphical software.

Cara menggunakan geojson mongodb

Share entire documentation as HTML

Much better option than just an image is to share the entire data dictionary and all diagrams in interactive HTML documentation. To export documentation, choose Export from the ribbon.

Cara menggunakan geojson mongodb

Then choose HTML Basic, then click Next on the following pages and select the path and a name on the Choose folder page. Confirm with Export and your documentation will be generated.

Cara menggunakan geojson mongodb

The result is this – interactive, searchable, lightweight HTML documentation.

Cara menggunakan geojson mongodb

Cara menggunakan geojson mongodb

Share entire documentation in PDF

You can also export documentation to PDF document. Process is like exporting HTML, except in this case you choose PDF option.

Cara menggunakan geojson mongodb

Cara menggunakan geojson mongodb

PDF includes ER Diagrams and data dictionary.

Cara menggunakan geojson mongodb

There you have it – a complete guide on how to build a diagram. Now it’s time for you to create your first diagram for MongoDB.

Create your first diagram for MongoDB

[WEBINAR] From Schema Design to Schema Discovery in MongoDB

Watch a recording of Dataedo Expert Webinar with MongoDB expert - Daniele Graziani, Consulting Engineer at MongoDB, and learn about the backward world of schema in MongoDB. Daniele will share his experience from years of advising customers on implementation, transition to, and querying of their MongoDB databases.

Kapan harus menggunakan MongoDB?

Kapan Menggunakan MongoDB Misalnya kamu memiliki toko online yang ramai pelanggan yang setiap menitnya terdapat ada 100 data pelanggan yang masuk. Selain itu kamu juga bisa menggunakan MongoDB saat data yang didapatkan berkembang secara cepat dan memiliki struktur data yang kompleks.

MongoDB menggunakan bahasa apa?

MongoDB sendiri ditulis dengan bahasa C++ dan telah tersedia untuk berbagai jenis bahasa pemrograman. Fitur utama dari mongoDB antara lain: model document-oriented storage.

Apakah MongoDB gratis?

MongoDB adalah software sistem database yang bisa Anda gunakan gratis, baik untuk pengguna Windows, Linux atau macOS. Ini tentu pilihan yang cocok apabila Anda sedang mengerjakan project kecil atau pribadi dan tidak menyediakan anggaran khusus untuk membeli lisensi.

Jelaskan langkah langkah dalam instalasi MongoDB?

Proses Install MongoDB.
jika sudah selali mendownload klik program yang berektensi .msi maka akan muncul tampilan sepeti di bawah ini..
selanjutnya centang box “I accept …".
selanjutnya klik tombol Complate..
klik tombol Next >.
jika teman teman ingin sembari melakukan instalasi MongoDB Compass bisa centang box..