Easy Charting with MongoDB Chart
MongDB Chart is a very powerful tool to visualize your MongoDB data, no need to write code anymore to create line, bar, pie and any other chart, all can be done with a few clicks. In this article I’m going to use MongoDB Atlas a managed MongoDB service in the cloud. If you are new to MongoDB Chart (or even with MongoDB) and want to experiment with it I strongly suggest to start with Atlas, just register for an account and launch your MongoDB cluster instantly.
So here is our scenario, let say that we want to show list of books that display title, author and published year in a simple data grid. First thing first, create book collection in Atlas and insert following documents:
"title": "The DevOps Handbook",
"author": "Gene Kim, Patrick Debois, John Willis, Jez Humble",
"title": "The Rainbow Troops",
"author": "Andrea Hirata",
"title": "David and Goliath",
"author": "Malcolm Gladwell",
"title": "Lean UX, 2nd Edition",
"author": "Jeff Gothelf, Josh Seiden",
"author": "John P. Kotter",
Once all data successfully imported (or inserted) click on Charts icon to start working with chart, if this is your first time you’ll see empty dashboard. Dashboard is collection of charts in your project, meaning each project could have more than one dashboard and each dashboard has many charts that connected to one data source.
Data Source refer to collection or view and all fields exists in that collection or view can be used to construct a chart, to create data source click menu Data Sources on the left pane and click button Add Data Source. Select available MongoDB deployment as source then choose book collection that you’ve just created.
Next step is adding a new dashboard, click menu Dashboards then click button Add Dashboard, fill in title and description of your dashboard.
We have datasource and dashboard already, now it’s time to create and publish our book list chart. Click button Add Chart and you’ll be redirected to what I called design page, it’s a user interface to design and modify chart view with almost no coding skill required. Select [databaseName].book datasource and choose Text for the Chart Type, add fields title, author and year to category section (you can accomplish this by drag&drop each fields), you may also add title and description of the chart and modify field name to make it more nice, finally click Save button on the right corner to publish it.