Connect to MongoDB
Connect MongoDB to Retool and query and manage documents in your collections.
MongoDB is a document-oriented NoSQL database that stores data as flexible JSON-like documents. You can create a MongoDB resource to connect to a self-managed MongoDB server or a database hosted on MongoDB Atlas, and build apps and automations that use queries to read and write data.
What you can do with MongoDB in Retool
After you create a MongoDB resource in Retool, you can:
- Query collections with filters, projections, and sort options.
- Insert, update, and delete documents.
- Run aggregation pipelines to transform and analyze data.
- Build admin panels and dashboards backed by your collections.
Before you begin
To connect MongoDB to Retool, you need the following:
- Cloud
- Self-hosted
Cloud organizations can connect to a MongoDB server with a username and password or a connection string, or to MongoDB Atlas by signing in to Atlas. Select the option that matches your database.
- MongoDB server
- MongoDB Atlas
- MongoDB server: Version 3.6 or later.
- Credentials: A username and password with appropriate permissions, or a connection string that includes authentication.
- Network access: Your MongoDB server must accept connections from Retool's IP addresses.
- Retool permissions: Ability to create and manage resources in your organization.
- MongoDB Atlas account: Access to the Atlas organization, project, and cluster you want to connect to. Your account must be able to create database users and edit the project's IP access list.
- Cluster: A cluster that is ready and has a standard
mongodb+srvconnection string. - Retool permissions: Ability to create and manage resources in your organization.
- MongoDB server: Version 3.6 or later.
- Credentials: A username and password with appropriate permissions, or a connection string that includes authentication.
- Network access: Your MongoDB server must be reachable from your Retool instance.
- Retool permissions: Ability to create and manage resources in your organization.
Create a MongoDB resource
Follow these steps to create a MongoDB resource in your Retool organization.
Create a new resource
In your Retool organization, navigate to Resources in the main navigation and click Create new → Resource. Search for "MongoDB" and click the MongoDB tile to begin configuration.
Use folders to organize your resources by team, environment, or resource type. This helps keep your resource list manageable as your organization grows.
Configure general settings
Specify a name and description for the resource that indicates which database or cluster it connects to. The description provides more context to users about how to use the resource.
| Example name | Example description |
|---|---|
| User database | MongoDB database containing user profiles and preferences. |
| Product catalog | Read-only MongoDB database with product and inventory data. |
Configure resource credentials
- Cloud
- Self-hosted
- MongoDB server
- MongoDB Atlas
Configure the connection settings for your MongoDB resource.

MongoDB resource credentials.
Click Autofill using connection string to fill most connection fields from a MongoDB connection string.
mongodb+srv://admin:password@cluster0.example.mongodb.net/mydb?retryWrites=true&w=majority
Host
The hostname or IP address of your MongoDB server.
db.example.com
Connection format
Select the connection format that matches your MongoDB deployment.
| Format | Description |
|---|---|
Standard (mongodb) | For direct connections to a MongoDB server. Requires a host and port. |
DNS seed list (mongodb+srv) | For deployments that use DNS-based service discovery. |
Port
The port your MongoDB server listens on. Required for the Standard connection format. The default MongoDB port is 27017.
Default database
The name of the MongoDB database to connect to.
Database username and password
Enter the Database username and Database password for a MongoDB user with access to the database. Create a dedicated user for Retool rather than reusing an administrator account.
Mongo version
Select the integration version to use. Version 2 - v2 connector (MongoDB 3.6+) is the default. Select Version 1 - legacy connector (MongoDB 3.6+) only if you need the legacy integration. Both versions support MongoDB 3.6 and later.
Connection options
Additional connection string options to customize the connection. For SSL and TLS, use the Use SSL/TLS setting instead.
SSL/TLS
Configuring SSL/TLS is optional but highly recommended for production deployments.
Enable Use SSL/TLS to encrypt connections between Retool and your MongoDB server. Refer to the SSL/TLS documentation for more about working with certificates.
SSH tunnel
If your MongoDB server isn't publicly accessible, select Enable SSH tunnel to connect through a bastion host. Enter the Bastion host and Bastion port, then download Retool's public key and add it to your bastion host for a user named retool. Refer to the SSH tunnel documentation for details.
Configure advanced options
Configure optional settings available under the Advanced options section of the resource configuration form.
Type
Choose how the resource can be used. Read connection is for read-only access, and queries use raw statements. Write connection allows write operations, which you create with the query GUI to help prevent accidental destructive changes.
Disable converting queries to prepared statements
Retool converts queries to prepared statements by default to improve performance and prevent injection attacks. Enable this option only if your use case requires disabling that behavior.
Outbound region
If your organization uses outbound regions, select the region that should be used for requests to MongoDB. This controls which geographic region your requests originate from.
Test the connection
Click Test connection to verify Retool can connect to MongoDB. If the test fails, check the following:
- Network access: Ensure your MongoDB server accepts connections from Retool's IP addresses.
- Credentials: Verify the username and password are correct and the user has access to the specified database.
- Hostname and port: Confirm the hostname is correct and MongoDB is running on the specified port.
- Connection format: If you use DNS seed list, ensure your deployment supports
mongodb+srvconnections. - SSL/TLS: If your server requires SSL, enable Use SSL/TLS.
After testing the connection, click View in console to open the Debug Tools console. The console displays the test details, execution time, and error details if the test fails. This information is helpful for troubleshooting connection issues.
Save the resource
Click Create resource to save your MongoDB resource. You can now use it in queries across your Retool apps and automations.
If you left the resource name blank, Retool names the resource MongoDB Atlas.
Authenticate with MongoDB Atlas
Under Credentials, click Connect MongoDB Atlas. Retool saves the resource and asks you to confirm before it redirects you to MongoDB Atlas. Click Authenticate, sign in to Atlas, and approve access. Retool returns you to the resource and opens Configure MongoDB Atlas.
Retool uses your authorization to list the organizations, projects, and clusters you can access, and to configure the resource you choose. Retool never sees your Atlas sign-in credentials. The authorization belongs to your Retool user, so you don't sign in again each time you connect another Atlas resource.
After you authenticate with MongoDB Atlas, Retool configures and saves the resource for you. You don't need to enter connection details or click Create resource.
Connecting to Atlas creates a database user for Retool in your Atlas project. Deleting the Retool resource also deletes this database user. Your Atlas project, cluster, and data aren't deleted.
Choose a cluster and database access
After you return from Atlas, Retool opens the Configure MongoDB Atlas dialog.
- Choose the cluster to connect to and click Next.
- Choose what Retool can access. Retool creates a dedicated database user with the permissions you grant, scoped to that cluster.
Decide what to grant based on how you plan to use the resource, and refer to the MongoDB Atlas documentation for details on what Atlas supports.
| Setting | Description |
|---|---|
| Cluster | The Atlas organization, project, and cluster to connect to. Only clusters you have access to appear. |
| Database access | Grant access to All databases on the cluster, including databases you create later, or to Specific databases that you add by name. |
| Access level | Read for read-only access, or All for read and write access. Grant Read unless your queries need to write data. |
| Default database | The database that queries use unless they specify another one. With Specific databases, it must be one of the databases you added. |
Save and connect
Click Save and connect. Retool then:
- Creates a database user for this resource, with a generated password.
- Adds Retool's IP addresses to the Atlas project's IP access list.
- Saves the connection settings to the resource.
- Tests the connection.
Atlas can take up to a minute to apply a new database user and network access, so the test might retry before it succeeds. Retool doesn't display the generated password or connection string.
Configure the connection settings for your MongoDB resource.

MongoDB resource credentials.
Click Autofill using connection string to fill most connection fields from a MongoDB connection string.
mongodb+srv://admin:password@cluster0.example.mongodb.net/mydb?retryWrites=true&w=majority
Host
The hostname or IP address of your MongoDB server.
db.example.com
Connection format
Select the connection format that matches your MongoDB deployment.
| Format | Description |
|---|---|
Standard (mongodb) | For direct connections to a MongoDB server. Requires a host and port. |
DNS seed list (mongodb+srv) | For deployments that use DNS-based service discovery. |
Port
The port your MongoDB server listens on. Required for the Standard connection format. The default MongoDB port is 27017.
Default database
The name of the MongoDB database to connect to.
Database username and password
Enter the Database username and Database password for a MongoDB user with access to the database. Create a dedicated user for Retool rather than reusing an administrator account.
Mongo version
Select the integration version to use. Version 2 - v2 connector (MongoDB 3.6+) is the default. Select Version 1 - legacy connector (MongoDB 3.6+) only if you need the legacy integration. Both versions support MongoDB 3.6 and later.
Connection options
Additional connection string options to customize the connection. For SSL and TLS, use the Use SSL/TLS setting instead.
SSL/TLS
Configuring SSL/TLS is optional but highly recommended for production deployments.
Enable Use SSL/TLS to encrypt connections between Retool and your MongoDB server. Refer to the SSL/TLS documentation for more about working with certificates.
SSH tunnel
If your MongoDB server isn't publicly accessible, select Enable SSH tunnel to connect through a bastion host. Enter the Bastion host and Bastion port, then download Retool's public key and add it to your bastion host for a user named retool. Refer to the SSH tunnel documentation for details.
Configure advanced options
Configure optional settings available under the Advanced options section of the resource configuration form.
Type
Choose how the resource can be used. Read connection is for read-only access, and queries use raw statements. Write connection allows write operations, which you create with the query GUI to help prevent accidental destructive changes.
Disable converting queries to prepared statements
Retool converts queries to prepared statements by default to improve performance and prevent injection attacks. Enable this option only if your use case requires disabling that behavior.
Test the connection
Click Test connection to verify Retool can connect to MongoDB. If the test fails, check the following:
- Network access: Ensure your MongoDB server is reachable from your Retool instance's network.
- Credentials: Verify the username and password are correct and the user has access to the specified database.
- Hostname and port: Confirm the hostname is correct and MongoDB is running on the specified port.
- Connection format: If you use DNS seed list, ensure your deployment supports
mongodb+srvconnections. - SSL/TLS: If your server requires SSL, enable Use SSL/TLS.
After testing the connection, click View in console to open the Debug Tools console. The console displays the test details, execution time, and error details if the test fails. This information is helpful for troubleshooting connection issues.
Save the resource
Click Create resource to save your MongoDB resource. You can now use it in queries across your Retool apps and automations.
Interact with MongoDB data
Once you've created a MongoDB resource, you can interact with MongoDB data using Retool.
Retool recommends using the app builder so you can use natural language to build React-based apps using AI.
- To use MongoDB data in the app builder, reference the resource in the prompt with
@, such as@User database. Refer to the data and functions documentation to learn more. - For classic apps, workflows, and agents, refer to the resource query documentation to learn how to write a resource query.
Best practices
Follow these best practices to secure and manage your MongoDB resource.
- Apply least privilege: Grant the MongoDB user only the permissions Retool needs. Use read-only access for resources that only read data.
- Enable SSL/TLS: Encrypt connections to your MongoDB server, and validate the server certificate.
- Use an SSH tunnel for private servers: Keep your server off the public internet and connect through an SSH tunnel.
- Use resource environments: Configure multiple resource environments to maintain separate databases or credentials for production, staging, and development.
Related resources
Create a resource
Learn how to create and manage resources in Retool.
IP allowlist
Allow Retool's IP addresses to access your MongoDB server.
SSH tunnels
Connect to databases that aren't publicly accessible.
Resource environments
Configure separate credentials for production and non-production environments.
Connect to Apache Cassandra
Connect to another NoSQL database.
Retool community: MongoDB
Community discussions and solutions for connecting resources to Retool.
MongoDB documentation
Official MongoDB documentation and driver reference.