MongoDB has built-in mongodump and mongorestore utilities that can import and export data.
Note: Use the mongodump and mongorestore utilities of MongoDB 3.0 or later versions.
Back up user-created database data.
Connect to the user-created database and select an account with the relevant permissions. Then, run
mongodumpto export the content of the user-created database. For example, run the following statement to export all databases and create a backup file named
mongodump --host xxx:27017 --authenticationDatabase admin -u xxx -p xxx
For more information, see mongodump command documentation.
Import the backup file to ApsaraDB for MongoDB.
mongostorecommand based on the backup file created in the previous step to import all data to ApsaraDB for MongoDB. For example, run the following statement to import the entire database:
mongorestore --host dds-xxx:3717 --authenticationDatabase admin -u root -p xxx dump