Bulk Import

To migrate subscriptions from other notification systems, you can use mongoimportopen in new window. NotifyBC also provides a utility script to bulk import subscription data from a .csv file. To use the utility, you need

  • Software installed
    • Node.js
    • Git
  • Admin Access to a NotifyBC instance by adding your client ip to the Admin IP List
  • a csv file with header row matching subscription model schema. A sample csv file is providedopen in new window. Compound fields (of object type) should be dot-flattened as shown in the sample for field confirmationRequest.sendRequest

To run the utility

git clone https://github.com/bcgov/NotifyBC.git
cd NotifyBC
npm i && npm run build
node dist/utils/bulk-import/subscription.js -a <api-url-prefix> -c <concurrency> <csv-file-path>

Here <csv-file-path> is the path to csv file and <api-url-prefix> is the NotifyBC api url prefix , default to http://localhost:3000/api.

The script parses the csv file and generates a HTTP post request for each row. The concurrency of HTTP request is controlled by option -c which is default to 10 if omitted. A successful run should output the number of rows imported without any error message

success row count = ***

Field Parsers

The utility script takes care of type conversion for built-in fields. If you need to import proprietary fields, by default the fields are imported as strings. To import non-string fields or manipulating json output, you need to define custom parsersopen in new window in file src/utils/bulk-import/subscription.tsopen in new window. For example, to parse myCustomIntegerField to integer, add in the colParser object

  colParser: {
    ...
    , myCustomIntegerField: (item, head, resultRow, row, colIdx) => {
      return parseInt(item)
    }
  }