Refreshing the data in development and deployment

One common development activity is “refreshing” the data in your application. This is straightforward, but the steps are a bit different depending upon whether you are refreshing your local development environment or refreshing the deployed application.

Prerequisites

First, be sure that you have set up your system so that default data is loaded when the database is empty. In meteor-application-template-react, that code is located in Mongo.js and settings.development.json.

While it might be tempting to not bother with automatically loading sample data, resist this urge. Having a well crafted set of sample data that gets automatically loaded when the database is empty will help you find errors in your system more quickly and easily. You will work faster with good sample data.

Whenever you change the structure of your data model (i.e. you modify the set of fields associated with a collection, or add a new collection), you will need to update your sample data to conform to the new data model.

Development mode

Refreshing the database in development mode is very easy:

  1. Stop Meteor. Quit the meteor process by typing control-c.

  2. Clear the database. Clear the database by running meteor reset in the command line in the directory containing your app.

  3. Restart the app. Run meteor npm run start to run a script that will enable your system to be initialized with the data in your settings.development.json file.

  4. Verify the refreshed database. Use Robo 3T to inspect the server database running on localhost:3001 to verify that the database is refreshed correctly. See Understanding data in development for more details on how to do that.

Production mode

Refreshing the database in production mode (i.e. when the application is deployed at Digital Ocean) is also easy, but it has one additional step, and the common steps are accomplished a little differently:

  1. Update settings.json. The deployed application gets its default data from settings.json (or from an assets file, if there is a lot of data). So, your first step is normally to update this file to contain the most recent sample data.

  2. Stop Meteor. To stop the deployed Meteor application, invoke “mup stop” (or “mup.cmd stop” on Windows).

  3. Clear the database. To clear the database, you have a couple of options. One way is to use Studio3T to delete all the collections in your app’s database. A second way is to run the following ssh command, where “YOURAPP.COM” is replaced by your app’s host name and “APP-NAME” with your app’s name (in the mup.js file):

ssh root@YOURAPP.COM 'docker exec mongodb mongo APP-NAME --eval "db.dropDatabase();"'
  1. Restart the app. To restart the app, invoke “mup reconfig”. This will push the new settings and restart the app.

  2. Verify the refreshed database. Use Robo 3T to inspect the production database. See How to inspect your MongoDB database on Digital Ocean using Studio3T for details.