Download and Install
Install Dependencies
Ensure you have JDK version 8 or later installed in your development environment.
This guide shows you how to add the MongoDB Java driver dependencies using Maven or Gradle in an integrated development environment (IDE). We recommend that you use an IDE such as IntelliJ IDEA or Eclipse IDE. An IDE makes it more convenient to configure Maven or Gradle to build and run your project.
If you are not using an IDE, see Building Maven or Creating New Gradle Builds for more information about how to set up your project. See The MongoDB Reactive Streams Driver to download the driver and dependencies directly from Maven.
Add the Driver Bill of Materials
In your IDE, create a new Maven or Gradle project. Add the Bill of Materials (BOM) for MongoDB JVM artifacts to your project to organize dependency versions. The BOM simplifies dependency management by ensuring that you maintain consistent and compatible versions of dependencies, such as between the Java Reactive Streams driver and the core driver library. Use the BOM to avoid version conflicts and simplify upgrades.
Select from the following Maven and Gradle tabs to view instructions for adding the BOM for each dependency manager:
Add the following code to the dependencyManagement
list in your
pom.xml
file:
<dependencyManagement> <dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-bom</artifactId> <version>5.4.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Add the following code to dependencies list in your
build.gradle
file:
dependencies { implementation(platform("org.mongodb:mongodb-driver-bom:5.4.0")) }
To view a list of dependencies that the BOM manages, see the mongodb-driver-bom dependency listing on the Maven Repository website.
Install the Project Reactor Library
This guide uses methods from the Reactor library, a library based on the Reactive Streams specification.
Open a new Maven or Gradle project in your IDE. If you are using Maven, add the
following snippet to your pom.xml
:
<dependencyManagement> <dependencies> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-bom</artifactId> <version>2023.0.7</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Then, add the following to your pom.xml
dependencies list:
<dependencies> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-core</artifactId> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies>
To install Reactor using Gradle, see Getting Reactor in the Project Reactor documentation.
After you configure your dependencies, ensure they are available to your project by running your dependency manager and refreshing the project in your IDE.
Install the Java Reactive Streams driver
In your project, if you are using Maven, add the following to
your pom.xml
dependencies list:
<dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-reactivestreams</artifactId> </dependency> </dependencies>
If you are using Gradle, add the following to your
build.gradle
dependencies list:
dependencies { implementation 'org.mongodb:mongodb-driver-reactivestreams' }
Because you installed the BOM, you can omit a version in the Java Reactive Streams driver dependency entry. The version you specify in the BOM determines the dependency versions to install.
After you configure your dependencies, ensure they are available to your project by running your dependency manager and refreshing the project in your IDE.
After you complete these steps, you have a new project and the driver dependencies installed.
Note
If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.