[JAVA-2707] Add new MongoClient interface that doesn't include the legacy API Created: 14/Dec/17  Updated: 28/Oct/23  Resolved: 17/Jan/18

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Java9

 Description   

The current MongoClient API for the synchronous driver is a class that resides in the com.mongodb package in the driver module. It includes entry points to both the standard CRUD API via the getDatabase method as well as the legacy CRUD API via the deprecated getDB method. This was a reasonable approach when the 3.0 driver was released because we imagined that applications would slowly shift from the legacy API to the standard API, DAO by DAO, and it made sense for all of them to share a single MongoClient instance in order to avoid the overhead of two connection pools, two SDAM monitors, etc.

While this is still a valid use case, most new applications never touch the legacy API, and we don't even refer to it in the reference documentation. Furthermore, including both APIs in a single module means that we will be unable to create modular JAR files that work properly as Java 9 modules. That's because the Java 9 module system prohibits the same package from being included in multiple modules, and currently the Java driver has such a split of the com.mongodb package. The mongodb-driver-core JAR file contains foundational classes used within core, as well as the sync and async drivers, including

  • ReadPreference
  • ReadConcern
  • WriteConcern

while the mongodb-driver JAR file contains core classes for the high-level synchronous driver API, including

  • MongoClient
  • DB
  • DBCollection
  • DBObject

However, the standard CRUD API is defined in the com.mongodb.client package, and includes interfaces such as:

  • MongoDatabase
  • MongoCollection
  • FindIterable

The only thing missing is an entry point. To that end, I propose adding a new MongoClient interface to the com.mongodb.client package as an additional entry point to the standard CRUD
API, which specifically does not include the legacy API. Additionally, there will be a MongoClients factory class for MongoClient instances, modelled after the corresponding class in the mongodb-driver-async module.



 Comments   
Comment by Githook User [ 17/Jan/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: JAVA-2707: Add MongoClients factory and MongoClient interface to the driver module

This will allow new applications to have no dependencies on the legacy API.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/395406cea6c852c6c97d89564e52ec0f037ff2f4

Generated at Thu Feb 08 08:57:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.