Steps I used:
mongodump
- copy dump folder to another computer (for each collection I get .bson and metadata files)
mongorestore
myDumpFolder
I noticed the indexes are lost and _id
has new values after mongorestore
.
Can anyone share their restore experiences that restored both indexes and mongodb_id?
Best Answer
Can anyone share their restore experiences that restored both indexes and mongodb_id?
As per MongoDB documentation here By default, mongorestore looks for a database backup in the dump/ directory.
New in version 3.6:
All MongoDB collections have UUIDs by default. When MongoDB restores collections, the restored collections retain their original UUIDs. When restoring a collection where no UUID was present, MongoDB generates a UUID for the restored collection.
UUID() has the following syntax:
It's returns
A BSON UUID object
.@Will, As JJussi has already said that mongorestore should recreate all indexes what mongodump has recorded.
For Example
I have mongodump in my
C:\data\dump
folder. Which contains the database folder100YWeatherSmall
,citibike
,city
,ships
,video
with their (.bson & .json) file. These database I had already restored in MongoDB 3.6.Here again i am going to mongorestore to these databases dump file in MongoDB 3.6.
As you can see that mention all databases has already in MongoDB.
Note: Here I have highlighted the some database name due to security reason.
Here I am going to mongorestore through the below command.
video.movies
database dump restore report status100YWeatherSmall.data
database dump restore report statuscitibike.trips
database dump restore report statusHere you can noticed that all during
mongorestore
it's showingindex: _id_ dup key:
because that index: id is already exist in that database & collection .That means whatever mongodump has created the index:id & ObjectId that is same index:id & ObjectId is same mongorestore in MongoDB.
Here the below mention reports is the citibike.trips mongorestore complete mongodump restore reports.
For example here I have only mention the citibite.trips restore complete reports. The message is showing restoring indexes for collection citibike.trips from metadata.
So, as per above conclusion we can say that
mongorestore
, store the sameindex:_id_
&ObjectId
, whichmongodump
has created.For your further ref here , here and here