2 / 9
Dec 2024

Hi Team,

Can you please help me on restoring the Indexes alone using mongorestore command,

I am using mongo restore command to restore data and Indexes, the data is restored successfully, but the Indexes are getting failed, Can any of you suggest on how to run the restoration command for only Indexes alone.

And here are the details:
mongorestore version: 100.8.0
Database version of Source and Target are 6.0.19.

Once the source of the index error is corrected then just restoring the indexes can be completed by having just the metadata files of the dump present in a dump directory.

rsync --recursive --include="*.json" --exclude='*.bson' dump/ dump2 mongorestore "mongodb://host:port/" dump2

Sure @Fabio_Ramohitaj ,

So I am executing the below command to restore all the data and Indexes from production to stage database using the below command

nohup mongotools/mongodb-database-tools-rhel70-x86_64-100.8.0/bin/mongorestore mongodb+srv://<db_username>:<db_password>@dhb-stage-pl-0.a9242.mongodb.net/?appName=FF_STB --nsFrom PIMSPB.* --nsTo SIMSB.* --numParallelCollections=120 --numInsertionWorkersPerCollection=12 --gzip --dir /share/infa/Backup/mongo_export/PIMSPB_B/ --drop >> /share/infa/Backup/mongo_export/PIMSPB_B_log/SIMSB.log &

Then I have all my documents are restored successfully, the Index creation is failed with the below error.

Error: Failed: SIMSB.SSEGEB: error creating indexes for SIMSB.SSEGEB: create Index error: (DuplicateKey) Index build failed: a6754ab8-93a6-462d-9eca-5854e5819db9: Collection SIMSB.SSEGEB ( aa0b576b-5d8e-4b45-a1c7-0c1557d89ae6 ) :: caused by :: E11000 duplicate key error collection: SIMSB.SSEGEB index: ME_PART_NUMBER_1_SERIAL_NUMBER_1 dup key: { ME_PART_NUMBER: “09-7221-9-0006”, SERIAL_NUMBER: 5858 }
681134180 document(s) restored successfully. 0 document(s) failed to restore.

Can you please let me know if there is a way to restore only indexes.

Regards,
Dinesh S

Hi @Dinesh_Reddy_Sanikommu,
Remove the unique indexes from the prod environment and recreate them normal So that in the next dump and restore it won’t give you problems for example , or manually create the indexes on the staging environment so that you do not have to touch the production environment. There are several ways.

Finally, I suggest that you investigate the problem some more because it does not seem at all obvious to me that my answer is absolutely correct.

Best Regards

The dump, and the source collection, contains the duplicate. I suggest running validate on the source collection, the linked documentation explains how to best run this.

Fix the duplicate. Either in the source and dump it again or in restored collection and then create the indexes.

The error log (please follow formatting guidlines) indicates what document is preventing the index build. Removing one(possibly more) of the conflicting documents will resolve this.