Connect to and Query Data with Free SQL Tools
This tutorial guides you through connecting to a federated database instance with the free tools MongoDB JDBC Driver and DBeaver (Community Edition).
If you followed the Advanced Configuration guide, this tutorial also guides you through querying sample data.
Install Client Software
Install the following client software to connect to and query your data with Atlas SQL.
Install DBeaver
DBeaver is a free, universal database tool. You can use it to explore your sample data in this tutorial. Download and install DBeaver (Community Edition).
Install JDBC Driver
Download the latest MongoDB JDBC Driver version.
Verify the integrity of the downloaded package:
The MongoDB release team digitally signs all software packages to certify that a particular MongoDB package is a valid and unaltered MongoDB release. MongoDB signs each release branch with a different PGP key in
.asc
format.Run the following command to download the
.asc
file from the Maven Central Repository.curl -O https://repo1.maven.org/maven2/org/mongodb/mongodb-jdbc/2.1.2/mongodb-jdbc-2.1.2.jar.asc Run the following command to download then import the key file. Replace
{server_url}
with one of the current GPG key servers supported by Maven:keyserver.ubuntu.com
keys.openpgp.org
pgp.mit.edu
gpg --keyserver {server_url} --recv-keys 91A2157730666110 gpg: key 91A2157730666110: public key "Huan Li <huan.li@10gen.com>" imported gpg: Total number processed: 1 gpg: imported: 1 Run the following command to verify the MongoDB JDBC Driver installation file.
gpg --verify mongodb-jdbc-2.1.2.jar.asc mongodb-jdbc-2.1.2.jar GPG should return a response similar to the following:
gpg: Signature made Wed May 22 13:24:36 2024 MDT gpg: using RSA key 91A2157730666110 gpg: Good signature from "Huan Li <huan.li@10gen.com>" If the package is properly signed, but you don't yet trust the signing key in your local
trustdb
,gpg
will also return the following message:gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: D2C4 5B7E 66A5 DCA1 8B76 57A8 91A2 1577 3066 6110 If you receive the following error message, confirm that you imported the correct public key:
gpg: Can't check signature: public key not found
Connect to Your Federated Database Instance
To connect to your federated database instance from DBeaver:
In Atlas, go to your federated database instance for your project.
If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.
If it's not already displayed, select your project from the Projects menu in the navigation bar.
In the sidebar, click Data Federation under the Services heading.
The Data Federation page displays.
Select JDBC Driver.
Note
This tutorial uses the JDBC Driver to connect. See Connect Using the Atlas SQL Interface for alternative connection methods.
Connect from DBeaver.
Launch DBeaver.
Add a new driver.
In DBeaver, click Database and select Driver Manager from the dropdown menu.
Click New to open the Create new driver modal.
In the Settings tab, enter the following information:
Driver Name
MongoDB
Class Name
com.mongodb.jdbc.MongoDriver
In the Libraries tab, click Add File and add your JDBC driver
all.jar
file.Click Find Class.
Click OK. The Create new driver modal closes.
Create a database connection.
In DBeaver, click Database and select New Database Connection from the dropdown menu to open the Connect to a database modal.
From the list of databases, select the
MongoDB
database driver that you created in the previous step.If you don't see
MongoDB
, select the All category inside the modal.Click Next.
In the Main tab, enter the following information:
JDBC URL
Your connection string from step 5.
Username
The MongoDB user to connect with.
Password
The MongoDB user's password.
In the Driver properties tab, expand User Properties. Add the following key-value properties:
database
The name of your virtual database.
user
The MongoDB user to connect with. Not required if you entered a
Username
in the previous step.password
The MongoDB user's password. Not required if you entered a
Password
in the previous step.
Click Finish.
To learn more about the different methods you can use to connect to a federated database instance, see Connect Using the Atlas SQL Interface.
Run Atlas SQL Queries
To run Atlas SQL queries in DBeaver:
Example Atlas SQLQueries
If you followed the Advanced Configuration guide using sample data, try running the following Atlas SQL queries against the sample data in your federated database instance.
Otherwise, you can modify these example queries for your namespaces.
SELECT Statement
SELECT * FROM Sessions
Atlas SQL returns all documents from the Sessions
collection.
LIMIT Statement
SELECT * FROM Users LIMIT 2
Atlas SQL returns two documents from the Users
collection.
WHERE Statement
SELECT * FROM Users WHERE name = 'Jon Snow'
Atlas SQL returns documents from the Users
collection where the
user's name
is Jon Snow
.
For an Atlas SQL command reference, see Atlas SQL Language Reference.