MongoDB 数据迁移可以通过多种方式实现,以下是一些常见的方法:
mongodump
和 mongorestore
mongodump
和 mongorestore
是 MongoDB 自带的工具,用于备份和恢复数据。
mongodump --host <source_host> --port <source_port> --db <source_db> --out <output_directory>
mongorestore --host <destination_host> --port <destination_port> --db <destination_db> <output_directory>/<source_db>
mongoexport
和 mongoimport
mongoexport
和 mongoimport
是用于导出和导入 JSON 或 CSV 格式数据的工具。
mongoexport --host <source_host> --port <source_port> --db <source_db> --collection <collection_name> --out <output_file.json>
mongoimport --host <destination_host> --port <destination_port> --db <destination_db> --collection <collection_name> --file <input_file.json>
MongoDB Compass 是 MongoDB 的图形用户界面工具,支持数据的导入和导出。
还有一些第三方工具可以帮助进行 MongoDB 数据迁移,例如:
通过以上方法,你可以根据具体需求选择合适的方式进行 MongoDB 数据迁移。