§2024-11-03
¶ Transfer data to other system
- mongoexport
- Purpose: Used to export data from a MongoDB database to a JSON or CSV file.
- Usage: Typically used to create backups of collections or to transfer data to other systems.
- Example Command:
mongoexport --db myDatabase --collection myCollection --out myCollection.json
- Options: You can specify query filters, fields to include, and other options to customize the export.
- mongoimport
- Purpose: Used to import data from a JSON or CSV file into a MongoDB database.
- Usage: Often used for populating a database with initial data or updating existing collections.
- Example Command:
mongoimport --db myDatabase --collection myCollection --file myCollection.json
- Options: You can specify file format, unique key handling, and other parameters.
¶ Transfer data to the same mongoDB system
- mongodump
- Purpose: Creates a binary backup of a MongoDB database.
- Usage: Used to create backups of the entire database or specific collections, preserving data types and indexes.
- Example Command:
mongodump --db myDatabase --out /backup/dump
- Options: You can choose to dump specific collections or set compression options.
- mongorestore
- Purpose: Restores a database from a binary dump created by mongodump.
- Usage: Used to restore data from backups, allowing you to recover databases or collections.
- Example Command:
mongorestore --db myDatabase /backup/dump/myDatabase
- Options: You can specify whether to overwrite existing data, drop collections before restoring, and more.
¶Incremental Backups: ???
If you need to back up only changes made since the last backup, you may consider using oplog (if using replication) or perform periodic dumps rather than full dumps every time.
¶ mongosh