.. include:: /includes/unicode-checkmark.rst

===================
Java MongoDB Driver
===================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: twocols

Introduction
------------

The official MongoDB Java Driver providing both synchronous and asynchronous interaction with MongoDB.

- :java-docs:`Tutorials <driver/tutorials/>`

- :java-docs:`Usage Guide <driver/>`

- :java-docs:`API Documentation <apidocs/>`

- :java-docs:`Changelog <whats-new/>`

- `Source Code <https://github.com/mongodb/mongo-java-driver/>`__


Take the free online course taught by MongoDB
---------------------------------------------

.. list-table::

   * - .. cssclass:: bordered-figure
       .. figure:: /figures/M220J_hero.jpg

     - `M220J: MongoDB for Java Developers <https://university.mongodb.com/courses/M220J/about>`__

       Learn the essentials of Java application development with MongoDB.


Installation
------------

The recommended way to get started using one of the drivers in your project is with a dependency
management system. See
:java-docs:`Installation Guide <driver/getting-started/installation/>`


Connect to MongoDB Atlas
------------------------

.. include:: /includes/atlas-connect-blurb.rst

.. code-block:: java

   import com.mongodb.ConnectionString;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoDatabase;
   import com.mongodb.MongoClientSettings;

   // ...
   ConnectionString connString = new ConnectionString(
       "mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
   );
   MongoClientSettings settings = MongoClientSettings.builder()
       .applyConnectionString(connString)
       .retryWrites(true)
       .build();
   MongoClient mongoClient = MongoClients.create(settings);
   MongoDatabase database = mongoClient.getDatabase("test");


See :java-docs:`Connect to MongoDB <driver/tutorials/connect-to-mongodb/>`
for more ways to connect.


Compatibility
-------------

MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/mongodb-compatibility-table-java.rst

.. include:: /includes/older-server-versions-unsupported.rst

.. [*] The 2.14 driver does not support all MongoDB 3.2 features (e.g.,
   read concern); however, if you are currently on a version 2.x driver
   and would like to run against MongoDB 3.2 but cannot upgrade to driver
   version 3.2, use the 2.14 driver.

Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/extracts/java-driver-compatibility-matrix-language.rst

.. include:: /includes/language-compatibility-table-java.rst

.. include:: /includes/help-links-java.rst
