Quick Start: Progress® DataDirect® for JDBC™ for MongoDB™ Driver

The following information enables you to connect with and test your driver immediately after installation. For installation instructions, refer to the Progress DataDirect for JDBC Drivers Installation Guide. This Quick Start covers the following topics:

Connecting to a Database

Testing the Connection

Tuning the Driver for Optimal Performance

Connecting to a Database

Once the driver is installed, you can connect from your application to your data store in two ways: using the JDBC Driver Manager or using a JNDI data source. The following section provides information you need to get started using the driver with the Driver Manager. For information on using data sources, refer to the Progress DataDirect for JDBC for MongoDB User's Guide.

Environment Setup

Set your system CLASSPATH to include the following entry:

install_dir/lib/mongodb.jar
Windows Example
CLASSPATH=.;C:\Program Files\Progress\DataDirect\JDBC_60\lib\mongodb.jar
UNIX/Linux Example
CLASSPATH=.:/opt/Progress/DataDirect/JDBC_60/lib/mongodb.jar

Driver Manager

To establish a database connection using the Driver Manager, your application must register the class name of the JDBC driver with the Driver Manager using the Class.forName() method and specifying the driver class name as the argument. The application must then invoke the DriverManager.getConnection() method supplying a connection URL.

IMPORTANT: Java SE 6 and higher automatically registers the driver with the JDBC Driver Manager. Therefore, if you are using Java SE 6 or higher as a JVM, you do not need to register the driver and can skip this step.

The classname and connection URL syntax for the MongoDB driver are:

Driver Classname:

com.ddtek.jdbc.mongodb.MongoDBDriver

Connection URL:

jdbc:datadirect:mongodb://<host>:<port>;[property=value[;...]]

For example, a connection URL might take the following form:

jdbc:datadirect:mongodb://MyServer:27017;DatabaseName=Test; SchemaDefinition=

Profile\\AppData\\Local\\Progress\\DataDirect\\MongoDB_Schema\\MyServer.config;
UserName=admin;Password=adminpass

NOTE: When first connecting to a MongoDB server, the driver automatically generates a SchemaDefinition for housing and sharing the normalized schema if one has not been specified in the connection string. The syntax for SchemaDefinition default values depends on your platform as follows:

For Windows

<application_data_folder>\Local\Progress\DataDirect\MongoDB_Schema\<hostname>.config

For UNIX/Linux

~/progress/datadirect/mongodb_schema/<hostname>.config

Refer to the User's Guide for a complete description of the connection URL syntax and descriptions of the connection properties that can be specified.

Example

// Register the driver with the driver manager.
// If using Java SE 6 or higher, you can omit this step. 
// Java SE 6 and higher automatically registers the driver. 
Class.forName("com.ddtek.jdbc.mongodb.MongoDBDriver");
// Establish the Connection
String url = "jdbc:datadirect:mongodb://MyServer:27017;DatabaseName=Test;
SchemaDefinition=
Profile\\AppData\\Local\\Progress\\DataDirect\\MongoDB_Schema\\MyServer.config;"
Connection con = DriverManager.getConnection(url, "test04", "test04");
// Verify the Connection
DatabaseMetaData metaData = con.getMetaData();
System.out.println("Database Name: " + metaData.getDatabaseProductName());
System.out.println("Database Version: " + 
metaData.getDatabaseProductVersion());

Testing the Connection

Take the following steps to test your connection with DataDirect Test™:

1.      Start DataDirect Test by running testforjdbc.bat or testforjdbc.sh in the install_dir/testforjdbc directory, where install_dir is your installation directory.

2.      Click Press Here to Continue.

3.      From the Connection menu, select Connect to DB.

4.      Select the appropriate template for your data source and specify values for the appropriate connection properties. Specify your user name and password if required. Click OK.

5.      A new connection window opens if the connection information was entered correctly. If the connection cannot be established, an error is displayed in the JDBC/Database Output window.

For more information about DataDirect Test, refer to the User's Guide.

Tuning the Driver for Optimal Performance

The driver has connection properties that directly affect performance. To tune the driver for optimal performance, set the following connection properties:

If you know the typical fetch size for your application

Set FetchSize to suit your environment. Smaller fetch sizes can improve the initial response time of the query. Larger fetch sizes improve overall fetch times at the cost of additional memory.

If your application retrieves large sets of data

Set ResultMemorySize to suit your requirements. This property specifies the maximum size (in MB) of an intermediate result set that the driver holds in memory. When this threshold is reached, the driver writes a portion of the result set to disk in temporary files. Increasing this value can improve performance by avoiding the need to page to disk. However, out-of-memory errors can occur when a result set exceeds the available heap size used by the JVM. Decreasing the value of ResultMemorySize reduces the risk of such out-of-memory errors.

By default, ResultMemorySize is a percentage of the max Java heap size. Therefore, as an alternative, you can increase max Java heap size to increase the maximum size of an intermediate result that the driver holds in memory. This can improve performance and reduce the likelihood of out-of-memory errors.

If your application uses statement pooling and the driver is not running from within an application server or from within another application that provides its own statement pooling

Set MaxPooledStatements to x where x is a positive integer that represents a number of pooled prepared statements.

If your application does not require the most recent version of data

Set ReadPreference to secondary or secondaryPreferred. When connecting to a replica set, reading from secondary members (read-only server nodes) can improve performance by distributing queries across secondary members and reducing the demand on the primary member (read-write server nodes).

© 2016. Progress Software Corporation. All rights reserved.