Dump You can dump the database locally using the following mongodump:
mongodump --host DATABASE_HOST --port PORT -d YOUR_DATABASE_NAME -u YOUR_DB_USERNAME -p YOUR_DB_PASSWORD This will create a dump folder containing a subfolder named after your database. The default port for MongoDB is 27017.
Import You can import the same dump to a local MongoDB instance using something like the following mongorestore after changing into the dump directory:
mongorestore --host DATABASE_HOST --port PORT -d DATABASE_NAME_TO_IMPORT_TO --drop DATABASE_NAME_TO_IMPORT_FROM Note: This will drop the collections in the DATABASE_NAME_TO_IMPORT_TO database before restoring the same collections from your database dump.
This is a useful tidbit of code to have until PHP adds this feature into their
MongoDB extension. I stumbled on an example on
illustration showing how to do this and rewrote it in what I think is a slightly
more modern way that does the same thing.