Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restore mongodb database .bson and .json files

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!

like image 582
hyperrjas Avatar asked Jan 03 '13 17:01

hyperrjas


People also ask

How do I restore a specific database in MongoDB?

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.

How do I restore a collection in MongoDB?

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.


1 Answers

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
like image 190
Jerry Avatar answered Oct 12 '22 01:10

Jerry