Import and Export with mongodump and mongorestore
Hello, I'm incompetent.
This is a memo on how to migrate a DB to a migration destination in MongoDB.
First, I want to use the command in the title, so I'll install `mongodb-tools-bin`.
yay -S mongodb-tools-bin
Source
With MongoDB running, use `mongosh`.
Then, check the DB.
test> show dbs
admin 40.00 KiB
~~~
Here, I'll try `admin`.
test> use admin
switched to db admin
admin> show tables
system.version
admin> db.system.version.find()
[ { _id: 'featureCompatibilityVersion', version: '7.0' } ]
So, if you confirm the contents with these steps and there are no mistakes, then `mongodump`.
mongodump --db admin --out ./
Set the path and DB name according to your environment, and this should produce the output.
Once output, move it to the migration destination using `scp` or some other method.
Destination
Just this.
mongorestore --uri="mongodb://127.0.0.1:27017/admintest" /path/to/admindatabase
Set the MongoDB connection destination and import destination (e.g., `admintest` in the above case) accordingly,
and change `/path/to/admindatabase` to the specified location.
Check the contents using the same steps as before.
That's all.
Looking forward to next time.