Database Configuration

GlobalForms stores its own data in MongoDB. It can also connect to SQL databases so forms can read from and write to your business systems. This page covers both connections.

Which database is used for what

Database

Used for

Configured in

MongoDB

GlobalForms data: forms, submissions, users and roles. Required.

mongo

Microsoft SQL Server

SQL Query form actions and SQL data lookups (Resquel)

settings.databases.mssql and settings.resquel

MySQL / MariaDB

SQL Query form actions and SQL data lookups (Resquel)

settings.databases.mysql and settings.resquel

PostgreSQL

SQL Query form actions and SQL data lookups (Resquel)

settings.databases.postgresql and settings.resquel

All of these settings go in config\local.json. Restart the GlobalForms service after any change. See Configuration Files.

MongoDB

GlobalForms normally uses the MongoDB server that GlobalCapture installs, with its own database on that server. A standalone MongoDB server is only for upgrades where GlobalCapture can't be updated yet; see System Requirements.

Setup writes the MongoDB connection to local.json from the values you enter during installation. To change it later, for example after moving MongoDB to another server, edit the mongo setting.

JSON
{
  "mongo": "mongodb://db-server:27017/GlobalForms"
}

The value is a standard MongoDB connection string:

mongodb://[username:password@]host[:port]/database[?options]

Situation

Example

No authentication

mongodb://db-server:27017/GlobalForms

With a database user

mongodb://svc_globalforms:<password>@db-server:27017/GlobalForms?authSource=admin

With TLS encryption

mongodb://svc_globalforms:<password>@db-server:27017/GlobalForms?authSource=admin&tls=true

  • authSource is the database that holds the MongoDB user, usually admin.

  • If the password contains special characters such as @, : or /, URL-encode them (for example @ becomes %40).

  • Use a dedicated MongoDB user for GlobalForms with access only to its database.

Standalone MongoDB: create a database user

If you run GlobalForms on a standalone MongoDB server that you manage, turn on MongoDB authentication and create a user that can read and write only the GlobalForms database. Connect with mongosh as a MongoDB administrator and run:

JavaScript
use admin
db.createUser({
  user: "svc_globalforms",
  pwd: passwordPrompt(),
  roles: [ { role: "readWrite", db: "GlobalForms" } ]
})

Enter the password when prompted. Then use this user and password during GlobalForms setup, with authSource set to admin. If your GlobalForms database has a different name, use that name in db.

Do not change mongoSecret. Setup generates this key to protect sensitive values stored in MongoDB. Keep it private and keep a secure copy of local.json. If you move GlobalForms to a new server, copy the same mongoSecret.

If GlobalCapture uses the same MongoDB server, update GlobalCapture before GlobalForms whenever you upgrade.

SQL connections for SQL Query actions

The SQL Query form action runs a SQL statement when a form is submitted, for example to save data or generate an ID. It uses the connections in settings.databases, one per database type: mssql, mysql or postgresql.

JSON
{
  "settings": {
    "databases": {
      "mssql": {
        "host": "sql-server",
        "port": "1433",
        "database": "FormsData",
        "user": "svc_globalforms",
        "password": "<password>"
      },
      "postgresql": {
        "host": "pg-server",
        "port": "5432",
        "database": "forms_data",
        "user": "svc_globalforms",
        "password": "<password>"
      }
    }
  }
}

Setting

Description

host

Server name or IP address. localhost and 127.0.0.1 are not accepted; use the server's name even if the database is on the same server.

port

1433 (SQL Server), 3306 (MySQL), 5432 (PostgreSQL)

database

Default database. A query can also name another database the user can access.

user, password

The database login

All five settings are required for a database type to appear in the SQL Query action. For SQL Server, TCP/IP connections must be enabled and SQL Server authentication allowed. See SQL Query Form Actions.

SQL connections for data lookups (Resquel)

To let forms read data from SQL, for example to fill a Select list from a table, you define queries as GlobalForms routes in settings.resquel. Resquel supports SQL Server, MySQL, MariaDB and PostgreSQL. See Setting Up SQL Lookups (Resquel).

Security recommendations

  • Create a dedicated database account for GlobalForms. Do not use sa, root or other administrator accounts.

  • Grant only the permissions your forms need, such as read-only access for lookups.

  • Use encrypted connections where your database supports them.

  • Limit who can read config\local.json, because it contains database passwords.

Troubleshooting

Symptom

Cause and fix

The service stops after changing mongo

GlobalForms cannot reach MongoDB. Check the host, port, user, password and authSource, and that the MongoDB port is open. Check logs\service.err.log.

Authentication failed for MongoDB

Check authSource and URL-encode special characters in the password.

A database type is missing from the SQL Query action

One of its five settings is empty. Complete them and restart the service.

Invalid SQL Host

The host is localhost or 127.0.0.1. Use the server's name or network address.

A SQL Query action fails

Test the same login and query in your database tool. Check that the database accepts network connections and that the firewall allows the port.

Login failed for a SQL Server user

SQL Server may be set to Windows authentication only. Enable SQL Server and Windows Authentication mode.