I successfully installed mongodb-charts and was able to create a dashboard also.
Now I want to save/export this dashboard to JSON(or any other format). Is there a feature to save/export and load/import Mongodb charts ? This would be useful if I want the same dashboard on some other server.
Also There was no tag for mongodb-charts. So any one with tag creation privilege can please create the tag.
MongoDB Charts is in beta release only.
It is designed for MongoDB Atlas and according to the official page "Share dashboards and collaborate" you can share dashboards and charts by adding new users and giving them permissions on the dashboard view "Access" button.
In Access view you can make your dashboard fully public by selecting "Everyone" option and choose permissions rights or just share with specific users.
As a hack, if you want to convert your dashboard into JSON format and transfer from one instance of MongoDB Charts to another, you can try mongodump "metadata" database in your MongoDB instance connected to MongoDB Charts.
It has 4 collections:
But all relationships are made through GUID ids, so without manual editing you can easily corrupt data during mongorestore.
UPDATE: The following bash script shows how to export dashboard and chart for migrating data to different MongoDB Charts instance:
# Your Dashboard and Chart names you want to export
dashboard_name="My Dashboard"
chart_name="My Chart"
# Exporting to `tmp` folder data from dashboard collection
mongodump --db metadata --collection dashboards --query "{"title": '$dashboard_name'}" --out "/tmp/"
dashboard_id=$(mongo --quiet --eval "db.getSiblingDB('metadata').dashboards.findOne({'title': '$dashboard_name'}, {'id': 1})['_id']")
# Exporting to `tmp` folder data from items collection
mongodump --db metadata --collection items --query "{\$and: [{'title': '$chart_name'}, {'dashboardId': '$dashboard_id'}]}" --out "/tmp/"
# After the following data is restored to different MongoDB Charts instance
# you need to make sure to modify the following records in imported data
# according to your datasource in new MongoDB Charts instance.
# for dashboards collection modify GUID for the following fields according to new datasource:
mongo --quiet --eval "db.getSiblingDB('metadata').dashboards.findOne({'title': '$dashboard_name'}, {'owners': 1, 'tenantId': 1, 'itemSummary.dataSourceId': 1})"
# for items collection modify GUID for the following fields according to new datasource:
mongo --quiet --eval "db.getSiblingDB('metadata').items.findOne({\$and: [{'title': '$chart_name'}, {'dashboardId': '$dashboard_id'}]}, {'dataSourceId': 1, 'tenantId': 1})"
Remember, this approach is not official and it is possible to corrupt your data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With