Connect MongoDB
A MongoDB source reads a MongoDB server or a MongoDB Atlas cluster into the Lake. The form has the steps General, Connection and Review: paste a connection URI or fill in the server fields, choose how to authenticate, and set the advanced driver options.
Add a MongoDB source
- Open Lake and click Add datasource in the header, or open the New menu in the toolbar above the tree.
- Choose MongoDB in the picker. Supported connectors shows how the picker is grouped. The form opens on the General step.
- On General, enter Name and Code and choose a Folder if you want one, then click Next. Add a data source explains these shared fields and their rules.
- On Connection, fill in the Server and Authentication cards, the Advanced section and the Test connection card, in that order. Test connection is optional.
- On Review, check the summary and click Add.
Fill in the Server card
- Connection type: Standard (mongodb://) connects to a server or replica set reached by host and port. Atlas, DNS seed list (mongodb+srv://) is for MongoDB Atlas and other SRV clusters, where DNS supplies the hosts and port.
- Paste connection string: click this link above the fields to open a paste row. Paste a
mongodb:// or mongodb+srv:// URI and click Fill, or press Enter. The URI fills the connection type, host, port, database, user, password and the options it can read, such as authSource, replicaSet and tls. If no host can be found, the row reads "No host found. Paste a mongodb:// or mongodb+srv:// URI."; press Escape or click Cancel to close it.
- Host or Cluster host: the standard form asks for Host (placeholder
Server name or IP address); Atlas asks for Cluster host, such as cluster0.example.mongodb.net. The form reads Host is required when it is empty. On an SRV connection enter the host name only; a port or a comma in the field reads "Enter only the cluster host name - SRV records supply the port".
- Port: shown on standard connections and starts on
27017. Enter a whole number no larger than 65535; the form reads Port is required when the value is missing or not a whole number, and Port must be 65535 or lower when it is too large.
- Database: optional. Every database the user can read is listed either way; leave it empty to use them all, and the summary shows All databases for an empty value.
Choose authentication
- Authentication starts on Username & password, which signs in as a database user (SCRAM); this is the usual choice. Choose No authentication only for servers that accept connections without a user; the choice clears the password.
- In Username & password mode, fill in Username and Password. Both are required: the form reads Username is required or Password is required when one is empty.
- After the source is saved, the form never shows the password again: the field reads Stored password with Replace. If your administrator turned on the re-entry setting, changing Host or Username clears the stored value and asks for it again; Connect a database covers stored passwords and keys in general.
Set the advanced options
The Advanced section starts collapsed and opens by itself when one of its values is set.
- Auth source (username and password mode): the database that holds the user. It defaults to the database you set, or
admin when none is set.
- Replica set (standard connections): the name of the replica set, for example
rs0.
- TLS/SSL (standard connections): encrypts the connection to the server. An Atlas connection shows the badge TLS is always on for SRV instead of the switch.
- CA certificate (PEM, optional): appears while TLS is on, including on an Atlas connection. Paste the certificate text or click Upload .pem; it is needed only when the server certificate is not issued by a public authority. If the file cannot be read, the field reads "Could not read the certificate file:" and the reason. Turning TLS/SSL off on a standard connection clears the certificate.
- Server version (standard connections): 4.2 or newer uses the default driver; 4.0 or older uses the compatibility driver for servers the default driver no longer supports. An Atlas connection does not offer this choice and turns the compatibility driver off.
Test the connection
The Test connection card sits at the foot of the Connection step and starts as Not tested.
- Click Test connection; while it runs, the button reads Testing…. The test is optional, so you can continue without it.
- A passing test reads Connection test passed. A failing test reads Connection test failed, with the server's message and a copy button. Correct the settings and test again, or read Lake troubleshooting.
Review and save
The Summary card lists the source: Name, Connection type, Host, Database and Authentication, then Auth source or Replica set when they are set, TLS, and Server version when the compatibility driver is chosen.
- On a standard connection, Host reads
host:port; on Atlas it reads the cluster host.
- Database reads All databases when it is empty, and Authentication reads the user name or None.
- TLS reads Off, On or Always on (SRV), and adds , custom CA certificate when a certificate is set.
- The Connection test row reads Passed, Failed or Not tested.
Click Add to create the source. Once it is saved, import its tables.
Edit or duplicate
- Opening a saved source lands on the Connection step with the password masked, the Name and Code fields locked, and the submit button reading Save.
- Duplicate opens a copy with empty Name and Code, the rest of the connection loaded, and the submit button reading Duplicate.
Questions, answered
Which connection type should I pick?
Standard (mongodb://) connects to a server or replica set reached by host and port. Atlas, DNS seed list (mongodb+srv://) is for MongoDB Atlas and other SRV clusters, where DNS supplies the hosts and port.
What does a pasted connection string fill in?
It fills the connection type, host, port, database, user, password and the options it can read. Click Paste connection string, paste a mongodb:// or mongodb+srv:// URI and click Fill, or press Enter. If no host is found, the row reads "No host found. Paste a mongodb:// or mongodb+srv:// URI.".
Why is there no Port field on my Atlas connection?
SRV records supply the port, so the form asks for the Cluster host only and leaves the port out. Enter the host name alone; a port or a comma in the field reads "Enter only the cluster host name - SRV records supply the port".
Do I have to enter a database?
No. Database is optional and every database the user can read is listed either way. With no value, the summary shows All databases.
When should I choose No authentication?
Only for servers that accept connections without a user. The choice removes the Username and Password fields and clears the password. Switch back to Username & password for a database user (SCRAM), which is the usual choice.
My server runs MongoDB 4.0. What do I set?
Open Advanced and set Server version to 4.0 or older. It uses the compatibility driver for servers the default driver no longer supports. The choice is shown on standard connections only.
Can I turn TLS off for an Atlas connection?
No. An SRV connection always uses TLS and shows the badge TLS is always on for SRV instead of the TLS/SSL switch. The switch is shown on standard connections only.
Why did my CA certificate disappear?
Turning TLS/SSL off on a standard connection clears the certificate, because it only applies to an encrypted connection. Turn TLS back on and paste or upload the certificate again.
When do I need a CA certificate?
Only when the server certificate is not issued by a public authority. The field appears while TLS is on; paste the PEM text or click Upload .pem. If the file cannot be read, the field reads "Could not read the certificate file:" and the reason.
What is Auth source for?
It is the database that holds the user. Leave it empty to use the Database you set, or admin when no database is set.