Connect to MongoDB
Learn how to connect your MongoDB database to Retool.
You can connect to MongoDB and make it available as a resource. Once complete, you can write queries to interact with MongoDB.
Retool supports connecting to both managed and self-hosted MongoDB databases, including MongoDB Atlas Clusters and AWS DocumentDB. Retool uses version 4.1 of the MongoDB Node driver.
Requirements
All users for Retool organizations on Free or Team plans have global Edit permissions and can add, edit, and remove resources. If your organization manages user permissions for resources, you must be a member of a group with Edit all permissions.
To create your MongoDB resource, you need to know:
- Your MongoDB host.
- The connection format you want to use (Standard or DNS seed list).
- The Mongo version your database uses.
The connection format you choose determines the fields required to create the resource. You might also need a port number, default database, a username, and a password.
If MongoDB is behind a firewall, you must also allow access from Retool's IP addresses. Add these IP addresses to your firewall's allowlist before you create the resource.
1. Create a MongoDB resource
Retool can connect to almost any API or database, and has built-in integrations for popular data sources. Sign in to your Retool organization and create a new MongoDB resource from the Resources tab.
2. Configure the resource
Provide the necessary details to configure the resource so Retool can connect to MongoDB. Not all settings are required but refer to the MongoDB documentation to learn what is needed.
General
These settings configure the name and location of the resource within Retool.
Name
The name to use for the resource (e.g., MongoDB).
Folder
The folder in which to save the resource.
Description
A brief description of the resource (e.g., Customer data).
Credentials
These settings configure how Retool connects to MongoDB. You can configure the credentials manually or with a connection string.
Setting | Description | |
---|---|---|
Host | The URL or IP address. | |
Connection format | The connection format used to connect to MongoDB. Options include Standard (/data-sources/quickstarts/database/mongodb) and DNS seed list (/data-sources/quickstarts/database/mongodb+srv) . | |
Port | The port number. Only required when using the Standard (/data-sources/quickstarts/database/mongodb) connection format. | |
Default database | The name of the default database. | |
Database username | Your database username. | |
Database password | The password of the database user. | |
Mongo version | The range of supported MongoDB versions. | |
Connection options | Additional options for the MySQL connection. | |
Use SSL/TLS | Connect to your database with SSL/TLS. |
Advanced options
You can also configure the following advanced settings for MongoDB resources.
Setting | Description |
---|---|
Disable converting queries to prepared statements | This disables SQL injection protection to allow dynamically generated SQL using JavaScript. |
SSH tunnel | Enable SSH tunneling through bastion host. |
3. Save the resource
Click Create resource to complete the setup. You can then click either Create an app to immediately start building a Retool app or Back to resources to return to the list of resources.
Wrap up
Your MongoDB resource is now ready to use. To interact with MongoDB data, select the resource in the query editor. Retool supports v2 of MongoDB's Extended JSON syntax.