Exporting from MongoDB :
To export the database, simply tell mongodump which database (or collection) you want to export, and where to export it to. Mine was the fairquid database, so my command looks like this:
mongodump -d fairquid -o fairquidbackup
This dumps the fairquid database into the fairquidbackup directory. Take a look at what we have in that directory now:
fairquid
├── users.metadata.json
└── users.bson
└── products.metadata.json
└── products.bson
└── companies.metadata.json
└── companies.bson
└── system.indexes.bson
0 directories, 2 files
Some of the collection in my fairquid database are users, products, companies etc, however you'll see a .bson and .json file for each collection in your database, plus the system indexes collection. It is up to you whether you want to take individual collections, or a whole database, but bear in mind that your choice will dictate whether you get information about indexes etc when you import the data elsewhere.
Importing to MongoDB :
To import, simply use the mongorestore command, which accepts either a single .bson file representing a collection, or a directory containing multiple files. Here's my example:
mongorestore -d fairquid /path/to/fairquid
You can specify any database name and path to files you like, so for taking backups or restoring additional copies of a database, this can be really handy. The mongo commands are well-documented and I found them easy to work with.
Hopefully this helps you work with them too!
Please don't forgot to leave a comment if you like this post.
Chears :)
Happy Coding
To export the database, simply tell mongodump which database (or collection) you want to export, and where to export it to. Mine was the fairquid database, so my command looks like this:
mongodump -d fairquid -o fairquidbackup
This dumps the fairquid database into the fairquidbackup directory. Take a look at what we have in that directory now:
fairquid
├── users.metadata.json
└── users.bson
└── products.metadata.json
└── products.bson
└── companies.metadata.json
└── companies.bson
└── system.indexes.bson
0 directories, 2 files
Some of the collection in my fairquid database are users, products, companies etc, however you'll see a .bson and .json file for each collection in your database, plus the system indexes collection. It is up to you whether you want to take individual collections, or a whole database, but bear in mind that your choice will dictate whether you get information about indexes etc when you import the data elsewhere.
Importing to MongoDB :
To import, simply use the mongorestore command, which accepts either a single .bson file representing a collection, or a directory containing multiple files. Here's my example:
mongorestore -d fairquid /path/to/fairquid
You can specify any database name and path to files you like, so for taking backups or restoring additional copies of a database, this can be really handy. The mongo commands are well-documented and I found them easy to work with.
Hopefully this helps you work with them too!
Please don't forgot to leave a comment if you like this post.
Chears :)
Happy Coding