In this folder called my_backup
I have a mongodb database dump with all my models/collections for example:
admins.bson
admins.metadata.json
categories.bson
categories.metadata.json
pages.bson
pages.metadata.json
.
.
.
I have a database called ubuntu_development
on mongodb. I am working with rails 3 + mongoid
How can I import/restore all models/collections from the folder my_backup
to my database ubuntu_development
Thank you very much!
The basic way to restore a database is to use the mongorestore command to specify the backup directory (dump directory) without any options. This option is suitable for databases located in the localhost (127.0. 0.1) using the port 27017.
Run the MongoDB system command ps -ef | grep mongod to find the temporary recovery MongoDB instance location. Run the MongoDB mongodump command to create a dump file of any specific database or collection. Run the mongorestore command to restore the dump file into any MongoDB instance.
To import .bson files
mongorestore -d db_name -c collection_name path/file.bson
Incase only for a single collection.Try this:
mongorestore --drop -d db_name -c collection_name path/file.bson
To import .json files
mongoimport --db db_name --collection collection_name --file name.json
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