I need a tool for rapidly recreating the proper "schema" (such as it is) of MongoDB instances between environments that pre-creates the right DB names, collections, sets collection caps, and creates the indexes for each collection. I do NOT want to copy all of the data between the instances, though. Each env I manage has different data but the DB/collection/caps/indexes are all the same. Is there an easy way to do this, preferably a tool that exports a JSON doc of all the names, caps and indexes that can then be re-imported into a new instance?
Yes, mongodump does export the indexes created on the collection, and the indexes are restored with mongorestore along with the data.
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.
After I didn't find any appropriate tool, I dumped the database and restored it without data, so metadata is restored (particularly all the collections are created with apropriate indexes), but the collections are empty. This also can be applied to databases with data as well, so the indexes will be created on existing db if there is no conflict.
1.Make a dump with mongodump
2.Empty the data of collections
find ./dump -name '*bson' -type f -exec cp /dev/null {} \;
3.Restore the data to new db with mongorestore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With