|
14 | 14 | */ |
15 | 15 | package org.eclipse.jnosql.diana.mongodb.document; |
16 | 16 |
|
17 | | -import com.mongodb.MongoClient; |
18 | | -import com.mongodb.MongoClientOptions; |
| 17 | +import com.mongodb.MongoClientSettings; |
19 | 18 | import com.mongodb.MongoCredential; |
20 | 19 | import com.mongodb.ServerAddress; |
| 20 | +import com.mongodb.client.MongoClient; |
| 21 | +import com.mongodb.client.MongoClients; |
21 | 22 | import jakarta.nosql.Configurations; |
22 | 23 | import jakarta.nosql.Settings; |
23 | 24 | import jakarta.nosql.Settings.SettingsBuilder; |
@@ -93,14 +94,18 @@ public MongoDBDocumentCollectionManagerFactory get(Settings settings) throws Nul |
93 | 94 | .map(HostPortConfiguration::toServerAddress) |
94 | 95 | .collect(Collectors.toList()); |
95 | 96 | if (servers.isEmpty()) { |
96 | | - return new MongoDBDocumentCollectionManagerFactory(new MongoClient()); |
| 97 | + return new MongoDBDocumentCollectionManagerFactory(MongoClients.create()); |
97 | 98 | } |
98 | 99 |
|
99 | 100 | Optional<MongoCredential> credential = MongoAuthentication.of(settings); |
100 | | - MongoClient mongoClient = credential.map(c -> new MongoClient(servers, c, MongoClientOptions.builder().build())) |
101 | | - .orElseGet(() -> new MongoClient(servers)); |
102 | 101 |
|
103 | | - return new MongoDBDocumentCollectionManagerFactory(mongoClient); |
| 102 | + |
| 103 | + final MongoClientSettings mongoClientSettings = credential.map(c -> MongoClientSettings.builder().credential(c) |
| 104 | + .applyToClusterSettings(builder -> builder.hosts(servers))).orElseGet(() -> |
| 105 | + MongoClientSettings.builder() |
| 106 | + .applyToClusterSettings(builder -> builder.hosts(servers))).build(); |
| 107 | + |
| 108 | + return new MongoDBDocumentCollectionManagerFactory(MongoClients.create(mongoClientSettings)); |
104 | 109 | } |
105 | 110 |
|
106 | 111 | public MongoDBDocumentCollectionManagerFactory get(String pathFileConfig) throws NullPointerException { |
|
0 commit comments