我成功安装了mongodb-charts并且还能够创建仪表板。
现在我想将此仪表板保存/导出为 JSON(或任何其他格式)。是否有保存/导出和加载/导入 Mongodb 图表的功能?如果我想在其他服务器上使用相同的仪表板,这将很有用。

mongodb-charts 也没有标签。所以任何有标签创建权限的人都可以创建标签。
MongoDB Charts 仅处于测试版本。
它是为 MongoDB Atlas 设计的,根据官方页面“共享仪表板和协作”,您可以通过添加新用户并授予他们仪表板视图“访问”按钮的权限来共享仪表板和图表。
在访问视图中,您可以通过选择“所有人”选项并选择权限或仅与特定用户共享来使仪表板完全公开。
作为一种黑客手段,如果您想将仪表板转换为 JSON 格式并从一个 MongoDB Charts 实例传输到另一个实例,您可以尝试在连接到 MongoDB Charts 的 MongoDB 实例中使用 mongodump“元数据”数据库。
它有4个集合:
但所有关系都是通过 GUID id 建立的,因此无需手动编辑,您就可以在 mongorestore 期间轻松损坏数据。
更新: 以下 bash 脚本显示了如何导出仪表板和图表以将数据迁移到不同的 MongoDB Charts 实例:
# 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})"
Run Code Online (Sandbox Code Playgroud)
请记住,这种方法不是官方的,并且可能会损坏您的数据。
| 归档时间: |
|
| 查看次数: |
1327 次 |
| 最近记录: |