You are currently viewing an older version of the Java driver documentation.
For the most recent version of the reference documentation, see our MongoDB Java Driver documentation site.

Installation

The recommended way to get started using one of the drivers in your project is with a dependency management system.

There are two Maven artifacts available in the release. The preferred artifact for new applications is mongodb-driver-sync however, we still publish the legacy mongo-java-driver uber-jar as well as the mongodb-driver jar introduced in 3.0.

MongoDB Driver Sync

The MongoDB Driver mongodb-driver-sync is the synchronous Java driver containing only the generic MongoCollection interface that complies with a new cross-driver CRUD specification. It does not include the legacy API (e.g. DBCollection).

important

This is a Java 9-compliant module with an Automatic-Module-Name of org.mongodb.driver.sync.client.

The mongodb-driver-sync artifact is a valid OSGi bundle whose symbolic name is org.mongodb.driver-sync.


<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>3.11.3</version>
    </dependency>
</dependencies>

Note: You can also download the mongodb-driver-sync jar directly from sonatype.

If downloading mongodb-driver-sync manually, you must also download its dependencies: bson and mongodb-driver-core

MongoDB Driver Legacy

The MongoDB Legacy driver mongodb-driver-legacy is the legacy synchronous Java driver whose entry point is com.mongodb.MongoClient and central classes include com.mongodb.DB, com.mongodb.DBCollection, and com.mongodb.DBCursor.

important

While not deprecated, we recommend that new applications depend on the mongodb-driver-sync module.


<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-legacy</artifactId>
        <version>3.11.3</version>
    </dependency>
</dependencies>

Note: You can also download the mongodb-driver-legacy jar directly from sonatype.

If downloading mongodb-driver-legacy manually, you must also download its dependencies: bson and mongodb-driver-core

MongoDB Driver

The MongoDB Driver mongodb-driver is the updated synchronous Java driver that includes the legacy API as well as a new generic MongoCollection interface that complies with a new cross-driver CRUD specification.

important

mongodb-driver is not an OSGi bundle: both mongodb-driver and mongodb-driver-core, a dependency of mongodb-driver, include classes from the com.mongodb package.

For OSGi-based applications, use the mongodb-driver-sync or the mongo-java-driver uber jar instead.

It is also not a Java 9 module.

This module is deprecated and will no longer be published in the next major release of the driver (4.0).


<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver</artifactId>
        <version>3.11.3</version>
    </dependency>
</dependencies>

Note: You can also download the mongodb-driver jar directly from sonatype.

If downloading mongodb-driver manually, you must also download its dependencies: bson and mongodb-driver-core

Uber Jar (Legacy)

For new applications, the preferred artifact is mongodb-driver-sync; however, the legacy mongo-java-driver uber jar is still available. The uber jar contains: the BSON library, the core library, and the mongodb-driver.

Note

This is a Java 9-compliant module with an Automatic-Module-Name of org.mongodb.driver.sync.client.

The mongo-java-driver artifact is a valid OSGi bundle whose symbolic name is org.mongodb.mongo-java-driver.

important

This module is deprecated and will no longer be published in the next major release of the driver (4.0).


<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.11.3</version>
    </dependency>
</dependencies>

Note: You can also download the mongo-java-driver jar directly from sonatype.