Skip to main content

Create and connect MongoDB database

OGRRE requires a database to handle storage of records, projects, users, and more. It is configured to work with any MongoDB instance. MongoDB is a NoSQL database with cloud support and options for free tier databases. To learn more about MongoDB, click here. To learn how to configure OGRRE with your database, read the following tutorials.

Create a MongoDB database

  1. MongoDB can be set up locally or in the cloud. MongoDB Atlas allows users to create one free tier database cluster with the cloud provider of your choice. OGRRE depends on GCP for other cloud services, so if using Atlas, it likely makes the most sense to use GCP.

  2. To create a project and your free cluster, see the MongoDB documentation. The documentation also provides instructions on how to create a database user and connect to your database. To connect your database to OGRRE, you will need to create a database user.

  3. To connect to the database, you must also ensure that the IP address you want to connect from is added to the access list. In the case of OGRRE, the backend IP address must be added to this list to allow it to access and update the database records. For information on how to add an IP address, see here.

Initialize Database for OGRRE

It is necessary to add some initial collections to your database before running OGRRE. OGRRE stores teams, authorized users, and assigned roles/permissions in the MongoDB database, which must be availabe as collections called teams, users, and roles. Furthermore, there must be at least one team and one user associated with that team, as well as a list of roles that are specific to OGRRE. You can create these manually, or use the python script we have provided to create these documents for you. The script can be downloaded here. The script takes the following arguments:
  • team_name (-t): the initial team name [required]
  • email (-e): email of the initial user [required]
  • assigned_role (-a): The role for the user you are creating. If not provided, the user will be assigned the role of sys_admin which contains all system and team permissions [optional]
  • database_username (-t): Database username [required]
  • database_password (-e): Database user password [required]
  • database_connection (-e): Database connection string [required]
  • database_name (-e): Database name [required]

Environment variables for OGRRE

The OGRRE backend requires 4 environment variables from your MongoDB setup. As explained in the backend installation section, the following variables must go inside your .env file.
  • DB_USERNAME: The username for the database user you created.
  • DB_PASSWORD: The password for the database user you created.
  • DB_CONNECTION: The cluster host name.
  • DB_NAME: The name of the database inside your cluster that you would like to connect to.
Your MongoDB database connection uri should look like this, substituting the bracketed variables with your credentials:

mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<DB_CONNECTION>.mongodb.net