I have a problem restoring data using mongorestore:
First, I used this command to export the data and everything seems to work fine:
mongodump -h 127.0.0.1 -d backup -o ~/
Then, I executed this command many times to restore the data:
mongorestore -h 127.0.0.1 -d backup -dir ~/backup/
But got this error:
2023-07-21T06:05:16.168-0400 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2023-07-21T06:05:16.168-0400 building a list of collections to restore from /home/zdx/backup dir
2023-07-21T06:05:16.169-0400 **reading metadata for ir.backup from** /home/zdx/backup/backup.metadata.json
2023-07-21T06:05:16.170-0400 **restoring to existing collection ir.backup without dropping**
2023-07-21T06:05:16.170-0400 restoring ir.backup from /home/zdx/backup/backup.bson
2023-07-21T06:05:16.181-0400 continuing through error: E11000 duplicate key error collection: ir.backup index: _id_ dup key: { _id: ObjectId('64b5a5865e23e338c4fdfe27') }
2023-07-21T06:05:16.181-0400 continuing through error: E11000 duplicate key error collection: ir.backup index: _id_ dup key: { _id: ObjectId('64b5a643a374f41eff1c897e') }
2023-07-21T06:05:16.181-0400 finished restoring ir.backup (0 documents, 2 failures)
2023-07-21T06:05:16.181-0400 no indexes to restore for collection ir.backup
2023-07-21T06:05:16.181-0400 0 document(s) restored successfully. 2 document(s) failed to restore.
My problem is, I have specified the “backup” database, but the data is restored to the “ir” database, why?
Operating environment:
OS version: CentOS Linux release 7.2.1511 (Core)
Mongodb :
Current Mongosh Log ID: 64ba59fb42ffe11856bda7cb
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.1
Using MongoDB: 6.0.8
Using Mongosh: 1.10.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2023-07-21T05:52:46.578-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2023-07-21T05:52:46.579-04:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2023-07-21T05:52:46.579-04:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2023-07-21T05:52:46.579-04:00: vm.max_map_count is too low