DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Data Engineering
  3. Databases
  4. Diagrams and Data Explorer for MongoDB

Diagrams and Data Explorer for MongoDB

Think in schemas but got no relations? No problem. Visualize virtual foreign keys using DbSchema.

Wise Coders user avatar by
Wise Coders
·
Jul. 28, 15 · Tutorial
Like (2)
Save
Tweet
Share
5.89K Views

Join the DZone community and get the full member experience.

Join For Free

MongoDB stores information in a format based on JSON documents. The complexity of the documents increases if the number of sub-documents increases. Mastering such documents using diagrams may make your work much easier. DbSchema (www.dbschema.com) can represent the documents using diagrams. Let's consider this JSON document :

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",                                               _
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}

This will be represented in DbSchema as three entities, one for each sub-document.

Diagram for MongoDB

You may ask how is this possible, since MongoDB use no schema as relational databases does. Well, DbSchema does discover the schema by scanning the data. What to have to do is to start DbSchema, connect to the database (provide the host name where the database is running) and the job is done.

Inside DbSchema you may create further diagrams, with the entities you want. Diagrams are called 'layouts', because in each layout you can open different other tools, like Visual Query Builder, Query Editor or Relational Data Browse.

If your database is empty and you wish to create the collection above in the database, open a Query Editor inside DbSchema and execute the code bellow:


local.persons <<
[
  firstName: "John",
  lastName: "Smith",
  isAlive: true,
  age: 25,
  address: [
    streetAddress : "21 2nd Street",
    city : "New York",
    state : "NY",
    postalCode : "10021-3100"
  ],
  phoneNumbers: [
    [
      type: "home",
      number: "212 555-1234"
    ],
    [
      type: "office",
      number: "646 555-4567"
    ]
  ],
  children: [],
  spouse: null
]

DbSchema can execute JSON commands via Java Groovy, which is very similar with the MongoDB native language. The major difference is that arrays as [val1,val2,...] and maps are [key1:val1,key2:val2,...]. Read more about the possible commands on MongoDB page.

When leaving the application you can save the project including the diagrams to a project file. Next time when you start the application all diagrams will be as they were before.

Relational Data Browse

Relational Data Browse is a tool inside DbSchema for exploring data from multiple collections. The nice stuff about it is the fact that it can explore data from collections which are referring data from other collections.

To show this consider the two collections bellow. We see that the 'employee' collection is referring 'companies' via 'companyId'. This is a normalization of the information inside the database, so the information related to a company is stored only one time, in the companies collection and it is referred from the employees.

                        companies :
                        {
                           name : "Wise Coders",
                           address : "Wildstreet 12, Montdown 22334"
                        }

                        employees :
                        {
                           firstName : "John",
                           lastName : "Cary"
                           companyId : new ObjectID('559b957f4451301bdc0cae45')
                        }

In the image bellow we have the two collections employees and companies. We have create a virtual foreign key from employees to companies by drag and drop of the companyId over the _id fields. The virtual foreign key helped us to explore the data from the employees according to the currently selected data in companies.

Relational data browse for MongoDB

This foreign key will exists only in DbSchema. Using it we will be able to browse data from both collections and see for each employee the company data, without having to execute each time a separate query. The random data generator can be started from the right-click popup on any collection in the diagram, then open the second frame by pressing the foreign key arrow icon from the title of the first browse frame.

Notice that is no need to create the virtual foreign key each time we access the application. DbSchema saves the layouts ( diagrams ) and the schema into a project file which will be opened next time when accessing the application.

Query Editor

Beside diagrams and relational data browse, you can make use of the query builder and data loader for MongoDB. Using the Query Editor you can edit and execute queries based on Groovy language, a Java - compatible scripting language. The result is displayed as a nested table structure.

Query Editor for MongoDB

DbSchema is supporting most of the relational databases plus Mongo DB. The tool is commercial with a trial period of two weeks.

Data (computing) Database Diagram Relational database MongoDB

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Debugging Threads and Asynchronous Code
  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • A Brief Overview of the Spring Cloud Framework
  • API Design Patterns Review

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: