iam using mongodump,mongorestore.
i would like to know what kind of details from the collection are available in dump exported by mongodump command.
does it export all the index created for specific fields in a collection?
iam using mongodump,mongorestore.
i would like to know what kind of details from the collection are available in dump exported by mongodump command.
does it export all the index created for specific fields in a collection?
Yes, mongodump
does export the indexes created on the collection, and the indexes are restored with mongorestore
along with the data. This is true with MongoDB v4.2.
@Prasad_Saya i don’t think it works like that for me. Below is the problem i’m facing.
Collection stats before export
Now i used mongorestore to import the file into another mongodb instance
mongorestore --db university --collection users /Users/dev/Documents/mongodb-performance-inputfiles/users.bson.gz --drop --gzip
After import i don’t see any indexes in stats.
i haven’t done any other steps to import users.metadata.json
what am i missing here?
should i import users.metadata.json
manually?
But i read in documentation like , we don’t need to import users.metadata.json
manually
my mongorestore logs shows no index to restore, but i have many index to restore as it is shown in my screenshots
I have a collection called as movie
with two documents and two indexes: the default index on _id
and an index on a field year
. I verified the data and indexes using the following methods from mongo
shell:
shell > db.movie.find()
shell > db.movie.getIndexes()
From the Windows OS command prompt:
os > mongodump --db=test --collection=movie
This created a folder dump\test
with two files: movie.bson
, and movie.metadata
. The folder and files are created in the directory from where I ran the mongodump
command.
Again, from the OS command prompt:
os > mongorestore --db=test --collection=movie_new dump/test/movie.bson
From the shell, I could verify:
shell > db.movie_new.find()
shell > db.movie_new.getIndexes()
i have to export with gzip option as the collection size is too large. i think with gzip option this doesn’t work.
I tried with --gzip
option. It worked in my environment correctly.
> mongodump --gzip --db=test --collection=movie
> mongorestore --gzip --db=test --collection=movie3 dump/test/movie.bson.gz
I could verify the restored movie3
collection and its indexes.
If your dump was gzip the metadata should be gzip too, was it uncompressed accidentally?
I can replicate no Indexes to restore
if I uncompress the metadata. When I gzipped it back up mongorestore created the indexes.
@chris my dump was gzipped but metadata is not gzipped. not sure why. may be its some mistake from my end,