The JDBC driver for MongoDB runs SQL queries against MongoDB for any Java application that supports JDBC. SQL support includes functions, expressions, aggregation, and joins including for collections with nested objects and arrays. See the features and SQL examples supported by the JDBC driver for MongoDB. The JDBC driver also supports the TokuMX MongoDB distribution.
Simple Licensing                              Download MongoDB               Getting Started
Terms and Agreement                            JDBC driver                       Get started in 5 minutes

Features
Access data in MongoDB collections via SQL including WHERE filters and ORDER BY.
Manipulate and control data using standard SQL functions not natively supported by MongoDB.
Perform SQL joins across MongoDB collections and databases.
Full support for nested documents (sub-documents) and arrays including filters and expressions.

How it works
The SQL query is validated and translated into a MongoDB query and executed using the MongoDB Java library.
The generated MongoDB query can be output in text form which provides a SQL to MongoDB translation tool and service.
Metadata is exposed to relational systems through JDBC by building a representative schema by sampling the datastore and fitting the least-general type that will represent the data.
SQL features not naitively supported by MongoDB and the JDBC driver are executed using the UnityJDBC virtualization engine.

Getting StartedStart using the JDBC Driver for MongoDB in 5 minutes:
Sample connection parameter usage:
// Specify debug mode, rebuild schema on every connection, and set location to cache schema jdbc:mongo://ds035438.mongolab.com:35438/tpch_writeable?debug=true&rebuildschema=true&schema=mongo:ds035438.mongolab.com:35438/tpch_writeable/myschemaSample connection parameter usage for cluster or sharded servers:
jdbc:mongo://<server1>:<port1>,<server2>:<port2>/<database>?<parameters>
Download the UnityJDBC installation package which contains the JDBC Driver for MongoDB, the MongoDB Java Driver version 2.12.2 distributed by MongoDB, and example Java programs demonstrating JDBC queries, metadata, arrays and nested objects, inserts, updates, and deletes,PreparedStatements (SELECT), PreparedStatements (INSERT/UPDATE/DELETE), translating SQL to Mongo queries, and DataSources, XADataSource, connection pooling using the JDBC driver. There are also sample Mongo code files for JSP and JSTL for use on Java web containers such as Tomcat. The sample programs can be run directly against a live database.
Configure the connection. The JDBC Driver for MongoDB can be used with any query or reporting software that supports JDBC. The connection information is:
JDBC Driver class name: mongodb.jdbc.MongoDriver URL format: jdbc:mongo://<serverName>/<databaseName>
As part of the connection string, a series of connection arguments can be passed into the driver that will affect its behavior. For sharded or cluster setup, the URL should contain the server names (and optional ports) in a comma-separated list.
Connector Argument Details

Connect to a database and run your queries. To help you take the JDBC Driver for MongoDB for a test drive, two MongoDB instances are provided for you at MongoLab (www.mongolab.com). Both instances are TPC-H databases.
The first instance is named tpch and is a read-only database for testing SELECT queries.
The second instance is named tpch_writeable and allows for both read and write operations.
tpch_writeable can be fully modified and can be used with SELECT, UPDATE, INSERT and DELETE queries. This instance is automatically refreshed every day.

The connection information for each database is
tpch URL: jdbc:mongo://ds029847.mongolab.com:29847/tpch tpch_writeable URL: jdbc:mongo://ds035438.mongolab.com:35438/tpch_writeableIf the submitted query cannot be natively handled by the JDBC Driver for MongoDB (such as for queries containing JOIN, GROUP BY or HAVING clauses), the query will be promoted to UnityJDBC for processing. UnityJDBC will parse the query into subqueries that will then be run on the specific MongoDB collection and process the intermediate results to produce the final result.
The 30-day trial version of the UnityJDBC driver for MongoDB has no row or feature limitations. After 30 days, the trial version has no expiration date and is fully functioning except that it is limited to returning up to 100 results. If your query produces more than 100 results, upgrade your MongoDB JDBC license here.
Code Walk through Class.forName(“mongodb.jdbc.MongoDriver”);
String url=”jdbc:mongo://ds029847.mongolab.com:29847/tpch”; con = DriverManager.getConnection(url, “dbuser”, “dbuser”);
stmt = con.createStatement(); String sql = “SELECT * FROM nation WHERE n_name >= ‘C’;”; rst = stmt.executeQuery(sql);
ResultSetMetaData meta = rst.getMetaData(); int numColumns = meta.getColumnCount(); System.out.print(meta.getcolumnName(1)); for (int j = 2; j <= meta.getColumnCount(); j++) System.out.print(“, ” + meta.getColumnName(j)); System.out.println(); while (rst.next()) { System.out.print(rst.getObject(1)); for (int j = 2; j <= numColumns; j++) System.out.print(“, ” + rst.getObjects(j)); System.out.println(); }
rst.close(); stmt.close(); con.close();Mongo and MongoDB are trademarks of 10gen, Inc.
Create a new instance of the JDBC Driver for MongoDB and make a connection.
Connect to the URL. The last part is the database name (tpch in this case).
Create a statement and submit a query. See the features and SQL examples supported by the JDBC driver for MongoDB.
Print out your results.
Close the statement and connection.
Setup Instructions
Setup Instructions for using the MongoDB JDBC Driver with Splunk
Setup Instructions for using the MongoDB JDBC Driver with SAP Lumira – using the MongoDB JDBC driver allows SAP Lumira to query MongoDB using SQL as well as MySQL, SQL Server, and multiple other data sources using UnityJDBC data virtualization
Setup Instructions for using the MongoDB JDBC Driver with SQuirreL SQL – the MongoDB JDBC driver is directly supported in SQuirreL SQLallowing SQL queries on MongoDB
Setup Instructions for using the MongoDB JDBC Driver with Eclipse SQL Explorer