Hi @Avalon_Zhou and welcome to MongoDB community forums!!
Firstly, thank you for recording this behaviour and reporting the error. I tried to reproduce the error using the command mentioned, and I am seeing the similar behaviour. The reason for that is the -dir
used in the mongorestore
command, is treated as -d ir which overwrites the database name as ir.
This has been reported internally and you can track any progress / updates with the following ticket TOOLS:3357.
One possible workaround here is to use the restore command as:
mongorestore -h 127.0.0.1 -d backup --dir ~/test/
which would restore as:
reading metadata for backup.sample from ........
Please test this workaround on a test environment to see if it works for you before proceeding to do it on a production environment.
Further, regarding the duplicate key error seen in the above logs is because mongorestore
would only perform the insert and would not perform any update operations. Please refer to the documentation on mongorestore Inserts Only for more information
You can refer to the response by @Prasad_Saya, our community user where he has described the same with a very efficient example.
Let us know of you have further questions.
Regards
Aasawari