MongoDB
MongoDB is a non-relational, NoSQL database. Unlike relational SQL databases like Microsoft SQL Server, MongoDB uses a JSON-like structure called collections instead of tables, with each JSON "row" referred to as a document. This in turn leads to lighter queries, helping optimize the performance of your Gateway and database connection.
Aside from a local installation, MongoDB can also be hosted in the cloud using the cloud service MongoDB Atlas. There are specific features which may draw users toward MongoDB Atlas, such as not needing to maintain a server or configure any clusters.
See the official MongoDB documentation for more information on MongoDB and MongoDB Atlas.
Module Information​
The MongoDB Cloud Connector module comes with Ignition Cloud Edition, but can also be used with a standard version of Ignition. Features of the MongoDB Cloud Connector include:
- Connectivity to MongoDB through the Gateway webpage interface.
- System functions to interact with connected MongoDB documents using a Python scripting API and expression language functions.
- A Perspective Binding that reads information from MongoDB documents to display on a component.
Gateway Interface​
After installing the MongoDB Cloud Connector, there will be new options available on the Gateway webpage's Status and Config pages.
Status Page​
The Gateway webpage's Status page will show information about your MongoDB connections. See the Connections - MongoDB page for more information.
Config Page​
The Gateway webpage's Config page will allow you to make connections from Ignition to MongoDB databases. To set up a MongoDB connection, navigate to the Gateway webpage's Config section > Connectors > MongoDB.
The table below outlines the properties available when creating or editing a MongoDB connection:
Property | Description |
---|---|
Name | The name of your MongoDB connection. |
Description | A description of your MongoDB connection. |
Connection Scheme | Prefix that identifies the connection format. Default is mongodb. Note: If you are creating a connection to MongoDB Atlas, you will need to change the Connection Scheme to mongodb+srv . |
Connection Hosts | Host or list of hosts to connect to, comma separated. If no port is specified, the default port of 27017 is used. |
Database | The name of the database to connect to. |
Username | The username to use when connecting. |
Change Password? | Check this box to change the existing password. This property will not be available for new connections. |
Password | The password to use when connecting. |
Password | Re-type password for verification. |
Connection Properties | Any extra connection properties you need to specify, such as enabling or disabling TLS.
|
Enabled | Enable or disable the database connection. Default is true. |
Connecting to MongoDB​
With the MongoDB Cloud Connector installed, you will be able to connect to a MongoDB database. The steps below outline how to connect to MongoDB. In this example, we will be connecting to MongoDB Atlas.
Get the Connection URL​
Go to your MongoDB Atlas Dashboard and click Database in the Deployment section.
On the Database Deployments window, click Connect.
You will be prompted to choose a connection method. Click Connect your application.
Choose Java for the driver, and select the latest version. Your connection URL will appear, giving you the information you need to connect Ignition to your MongoDB database.
Interpreting the Connection URL​
The connection URL will have all the information necessary to set up a basic connection. Note that you will still need to specify extra connection properties such as Transport Layer Security (TLS) or certificates should you need them.
Your connection URL will look something like the example below, with specific sections of the connection URL corresponding with specific Gateway fields from the MongoDB connection setup process.
mongodb+srv://<username>:<password>@<clustername.example.mongodb.net>/?retryWrites=true&w=majority
Gateway Field | Connection URL Value |
---|---|
Connection Scheme | mongodb+srv (or mongodb if not using MongoDB Atlas) |
Connection Hosts | <clustername.example.mongodb.net> |
Username | <username> |
Password | <password> |
Connection Properties | retryWrites=true&w=majority (You can also add extra connection properties here) |
Get the Database Name​
On the MongoDB Atlas Dashboard, navigate to Deployment > Database > Your Cluster Name > Browse Collections.
Your dashboard will list any existing databases within your cluster. Choose which database to connect to from this list. In this example, we will be using the sample_guides database.
Connect Ignition to MongoDB​
Navigate to Config > Connectors > MongoDB on the Gateway, and click Create new MongoDB Connector.
Fill out the Gateway fields with the appropriate information from your connection URL and the database name, then click Create New MongoDB Connector.
Your MongoDB connection is now created. It may take a few seconds for your connection to update to a "Valid" status.
MongoDB Perspective Bindings​
Users can pull data from a MongoDB database to populate Perspective components. MongoDB Perspective bindings are read-only, so users will not be able to write to collections from the binding itself. See the MongoDB Bindings in Perspective page for more details.
MongoDB System Functions​
While the MongoDB Perspective binding itself has no write capabilities, the included MongoDB System Functions allow users to read, update, delete, and take aggregates of collection documents. See the MongoDB System Function page for a list of available system functions.