36
36
37
37
import static com .mongodb .assertions .Assertions .notNull ;
38
38
import static java .util .Arrays .asList ;
39
+ import static java .util .Collections .singletonList ;
39
40
import static org .bson .codecs .configuration .CodecRegistries .fromProviders ;
40
41
41
42
/**
47
48
* MongoClient mongoClient1 = new MongoClient("localhost");
48
49
* MongoClient mongoClient2 = new MongoClient("localhost", 27017);
49
50
* MongoClient mongoClient4 = new MongoClient(new ServerAddress("localhost"));
50
- * MongoClient mongoClient5 = new MongoClient(new ServerAddress("localhost"), new MongoClientOptions.Builder ().build());
51
+ * MongoClient mongoClient5 = new MongoClient(new ServerAddress("localhost"), MongoClientOptions.builder ().build());
51
52
* </pre>
52
53
* <p>You can connect to a <a href="http://www.mongodb.org/display/DOCS/Replica+Sets">replica set</a> using the Java driver by passing a
53
54
* ServerAddress list to the MongoClient constructor. For example:</p>
@@ -171,9 +172,11 @@ public MongoClient(final ServerAddress addr) {
171
172
* @param credentialsList the list of credentials used to authenticate all connections
172
173
* @see com.mongodb.ServerAddress
173
174
* @since 2.11.0
175
+ * @deprecated Prefer {@link #MongoClient(ServerAddress, MongoCredential, MongoClientOptions)}
174
176
*/
177
+ @ Deprecated
175
178
public MongoClient (final ServerAddress addr , final List <MongoCredential > credentialsList ) {
176
- this (addr , credentialsList , new MongoClientOptions .Builder ().build ());
179
+ this (addr , credentialsList , MongoClientOptions .builder ().build ());
177
180
}
178
181
179
182
/**
@@ -195,11 +198,26 @@ public MongoClient(final ServerAddress addr, final MongoClientOptions options) {
195
198
* @param options default options
196
199
* @see com.mongodb.ServerAddress
197
200
* @since 2.11.0
201
+ * @deprecated Prefer {@link #MongoClient(ServerAddress, MongoCredential, MongoClientOptions)}
198
202
*/
203
+ @ Deprecated
199
204
public MongoClient (final ServerAddress addr , final List <MongoCredential > credentialsList , final MongoClientOptions options ) {
200
205
super (addr , credentialsList , options );
201
206
}
202
207
208
+ /**
209
+ * Creates a Mongo instance based on a (single) mongo node using a given server address, credential, and options
210
+ *
211
+ * @param addr the database address
212
+ * @param credential the credential used to authenticate all connections
213
+ * @param options default options
214
+ * @see com.mongodb.ServerAddress
215
+ * @since 3.6.0
216
+ */
217
+ public MongoClient (final ServerAddress addr , final MongoCredential credential , final MongoClientOptions options ) {
218
+ super (addr , singletonList (credential ), options );
219
+ }
220
+
203
221
/**
204
222
* <p>Creates an instance based on a list of replica set members or mongos servers. For a replica set it will discover all members.
205
223
* For a list with a single seed, the driver will still discover all members of the replica set. For a direct
@@ -234,7 +252,9 @@ public MongoClient(final List<ServerAddress> seeds) {
234
252
* @param credentialsList the list of credentials used to authenticate all connections
235
253
* @see MongoClientOptions#getLocalThreshold()
236
254
* @since 2.11.0
255
+ * @deprecated Prefer {@link #MongoClient(List, MongoCredential, MongoClientOptions)}
237
256
*/
257
+ @ Deprecated
238
258
public MongoClient (final List <ServerAddress > seeds , final List <MongoCredential > credentialsList ) {
239
259
this (seeds , credentialsList , new MongoClientOptions .Builder ().build ());
240
260
}
@@ -276,11 +296,35 @@ public MongoClient(final List<ServerAddress> seeds, final MongoClientOptions opt
276
296
* @param options the options
277
297
* @see MongoClientOptions#getLocalThreshold()
278
298
* @since 2.11.0
299
+ * @deprecated Prefer {@link #MongoClient(List, MongoCredential, MongoClientOptions)}
279
300
*/
301
+ @ Deprecated
280
302
public MongoClient (final List <ServerAddress > seeds , final List <MongoCredential > credentialsList , final MongoClientOptions options ) {
281
303
super (seeds , credentialsList , options );
282
304
}
283
305
306
+ /**
307
+ * <p>Creates an instance based on a list of replica set members or mongos servers. For a replica set it will discover all members.
308
+ * For a list with a single seed, the driver will still discover all members of the replica set. For a direct
309
+ * connection to a replica set member, with no discovery, use the {@link #MongoClient(ServerAddress, List, MongoClientOptions)}
310
+ * constructor instead.</p>
311
+ *
312
+ * <p>When there is more than one server to choose from based on the type of request (read or write) and the read preference (if it's a
313
+ * read request), the driver will randomly select a server to send a request. This applies to both replica sets and sharded clusters.
314
+ * The servers to randomly select from are further limited by the local threshold. See
315
+ * {@link MongoClientOptions#getLocalThreshold()}</p>
316
+ *
317
+ * @param seeds Put as many servers as you can in the list and the system will figure out the rest. This can either be a list of mongod
318
+ * servers in the same replica set or a list of mongos servers in the same sharded cluster.
319
+ * @param credential the credential used to authenticate all connections
320
+ * @param options the options
321
+ * @see MongoClientOptions#getLocalThreshold()
322
+ * @since 3.6.0
323
+ */
324
+ public MongoClient (final List <ServerAddress > seeds , final MongoCredential credential , final MongoClientOptions options ) {
325
+ super (seeds , singletonList (credential ), options );
326
+ }
327
+
284
328
/**
285
329
* Creates a Mongo described by a URI. If only one address is used it will only connect to that node, otherwise it will discover all
286
330
* nodes.
@@ -317,12 +361,31 @@ public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoD
317
361
* @param mongoDriverInformation any driver information to associate with the MongoClient
318
362
* @see com.mongodb.ServerAddress
319
363
* @since 3.4
364
+ * @deprecated Prefer {@link #MongoClient(ServerAddress, MongoCredential, MongoClientOptions, MongoDriverInformation)}
320
365
*/
366
+ @ Deprecated
321
367
public MongoClient (final ServerAddress addr , final List <MongoCredential > credentialsList , final MongoClientOptions options ,
322
368
final MongoDriverInformation mongoDriverInformation ) {
323
369
super (addr , credentialsList , options , mongoDriverInformation );
324
370
}
325
371
372
+ /**
373
+ * Creates a MongoClient to a single node using a given ServerAddress.
374
+ *
375
+ * <p>Note: Intended for driver and library authors to associate extra driver metadata with the connections.</p>
376
+ *
377
+ * @param addr the database address
378
+ * @param credential the credential used to authenticate all connections
379
+ * @param options default options
380
+ * @param mongoDriverInformation any driver information to associate with the MongoClient
381
+ * @see com.mongodb.ServerAddress
382
+ * @since 3.6
383
+ */
384
+ public MongoClient (final ServerAddress addr , final MongoCredential credential , final MongoClientOptions options ,
385
+ final MongoDriverInformation mongoDriverInformation ) {
386
+ super (addr , singletonList (credential ), options , mongoDriverInformation );
387
+ }
388
+
326
389
/**
327
390
* Creates a MongoClient
328
391
*
@@ -334,12 +397,31 @@ public MongoClient(final ServerAddress addr, final List<MongoCredential> credent
334
397
* @param options the options
335
398
* @param mongoDriverInformation any driver information to associate with the MongoClient
336
399
* @since 3.4
400
+ * @deprecated Prefer {@link #MongoClient(List, MongoCredential, MongoClientOptions, MongoDriverInformation)}
337
401
*/
402
+ @ Deprecated
338
403
public MongoClient (final List <ServerAddress > seeds , final List <MongoCredential > credentialsList , final MongoClientOptions options ,
339
404
final MongoDriverInformation mongoDriverInformation ) {
340
405
super (seeds , credentialsList , options , mongoDriverInformation );
341
406
}
342
407
408
+ /**
409
+ * Creates a MongoClient
410
+ *
411
+ * <p>Note: Intended for driver and library authors to associate extra driver metadata with the connections.</p>
412
+ *
413
+ * @param seeds Put as many servers as you can in the list and the system will figure out the rest. This can either be a list of mongod
414
+ * servers in the same replica set or a list of mongos servers in the same sharded cluster.
415
+ * @param credential the credential used to authenticate all connections
416
+ * @param options the options
417
+ * @param mongoDriverInformation any driver information to associate with the MongoClient
418
+ * @since 3.6
419
+ */
420
+ public MongoClient (final List <ServerAddress > seeds , final MongoCredential credential , final MongoClientOptions options ,
421
+ final MongoDriverInformation mongoDriverInformation ) {
422
+ super (seeds , singletonList (credential ), options , mongoDriverInformation );
423
+ }
424
+
343
425
/**
344
426
* Gets the options that this client uses to connect to server.
345
427
*
0 commit comments