mongoexport 将指定表中的数据导出为 JSON 格式。
使用 mongoexport 导出某个表的数据:
mongoexport --host=<ip> --port=<port> --username=<user> --password=<password> --authenticationDatabase=admin --db=<database> --collection=<collection> --out=xxx.json
执行完成后会在指定的输出文件中看到 JSON 格式的数据。
导出来的 JSON 数据可以通过 mongoimport 工具导入到其他实例或者其他表。
使用 mongoimport 将 JSON 数据导入到某个表中:
mongoimport --host=<ip> --port=<port> --username=<user> --password=<password> --authenticationDatabase=admin --db=<database> --collection=<collection> xxx.json
导入完成后,登录到目标实例上可以看到对应的库表中已经成功插入了数据。