You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two types of ``MongoClient`` because we wanted a cleaner API
213
+
for new users that didn't have the confusion of including multiple CRUD
214
+
APIs. We wanted to ensure that the new CRUD API was available in a Java
215
+
package structure that would work well with Java module support
216
+
introduced in Java 9.
217
+
218
+
Which type of ``MongoClient`` should I use?
219
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220
+
221
+
New applications generally use the
222
+
``com.mongodb.client.MongoClient`` interface, which supports:
223
+
224
+
- Configuration with ``MongoClientSettings`` and ``ConnectionString``. You can create instances of this interface via factory methods defined in the ``com.mongodb.client.MongoClients`` class.
225
+
- CRUD API using ``MongoDatabase``, and from there, ``MongoCollection``
226
+
227
+
Use the ``com.mongodb.MongoClient`` class if you require support for the legacy API, which supports:
228
+
229
+
- Configuration with ``MongoClientOptions`` and ``MongoClientURI``
230
+
- CRUD API using ``DB``, and from there, ``DBCollection``. You can access this API via the ``getDB()`` method.
231
+
232
+
For applications that require a mix of the new and legacy APIs, ``com.mongodb.MongoClient`` also supports:
233
+
234
+
- Configuration with ``MongoClientSettings`` and ``ConnectionString``, the only difference being that you create instances via constructors instead of a factory class.
235
+
- CRUD API using ``MongoDatabase``, and from there, ``MongoCollection``. You can access this API via the ``getDatabase()`` method.
236
+
237
+
How do I prevent the "java.lang.NoClassDefFoundError: com/mongodb/MongoClient" error?
0 commit comments