JDBC Driver for MongoDB®

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

Getting Started

MongoDB® JDBC Driver License Agreement

The trial version of the JDBC Driver for MongoDB is free to use and distribute in all situations. This includes distributing in open source and commercial products and use in commercial projects and systems.

Queries involving joins, aggregation, functions, and expressions that are not natively supported by MongoDB are executed by UnityJDBC. UnityJDBC provides cross-databases joins, query translation and virtualization, and simplifies integration of NoSQL and SQL data sources. The trial version has no limits for the first 30 days. After which, the driver will return at most 100 rows.

Developers and OEMs may license the full version of the MongoDB JDBC driver for a reasonable cost.

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.

The debug property will cause the driver to print out debug information to the console during its operation.

user

<username>

User name for connection.

password

<password>

Password for connection.

encoding

utf-8

Character encoding used.

dbname

<database>

Database name to use.

validation

strictflexnone

Schema validation performed. Strict validation ensures all identifiers are in the schema. Flex validation will perform best effort validation against a schema (if present) but attempt to execute the query in all cases. None will never generate or use any schema information.

schema

<file_location>

Location of schema. Either a file URI or location in MongoDB. If the MongoDB collection is read-only, a schema can be stored locally. A schema is required for query promotion to UnityJDBC. Default schema location is _schema in the current MongoDB database (requires write permissions to database).

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.

If 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.

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/myschema