Guide: How to export and import schema and data from MongoDB to MongoDB

Don’t try to export the schema or data via parse-dashboard. It will have the wrong format. Instead, follow the steps below.

To export and import only the schema without data:

  1. Download MongoDB compass GUI
  2. Launch Compass and connect to the existing DB using the uri string
  3. In the databases section select your database and click on _SCHEMA
  4. Click “Export collection” => “Export full collection” => JSON => save
  5. In the top left corner click “Connect” => “New connection”
  6. Connect to your new database using the uri string
  7. If in the databases section your database has no collections, then launch parse-dashboard with your new database’s uri string. This will create the default collections in your new database.
  8. In Compass click on the _SCHEMA of your new database and delete the contents.
  9. Click “Add data” and select the file you’ve previously exported from the existing database
  10. Refresh the window with parse-dashboard and you should see all the tables created from schema

To export and import data after the schema has been imported:

  1. Download MongoDB database tools Download MongoDB Command Line Database Tools | MongoDB
  2. Open command line interface and run this command
    mongoexport --uri="mongodb+srv://<yourExistingDBadminName>:<yourExistingDbPassword>" --collection=YourCollectionName --out=collectionName.json
  3. You need to run this command for every collection (table) that you want to export. Each collection saved to a separate json file.
  4. Open MongoDB compass and connect to your new database using uri string
  5. Select your new database and on the right of it click on the plus sign to add a collection
  6. Give your new collection a name
  7. Click “Add data” and import the content exported from the old database.
  8. Refresh the parse-dashboard window and you should see the content populated.
1 Like