0

I'm using mongo java driver 3.9.0 and the close() method from MongoClient is deprecated. The problem I see is that MongoClient implements Closebale, and that's why there is this close() method in there. I couldn't find any replace to it yet and I was looking here: http://mongodb.github.io/mongo-java-driver/3.9/javadoc/com/mongodb/Mongo.html#close--

How can I replace it so I don't have to use the deprecated method?

Thanks!

Igor
  • 1,397
  • 3
  • 24
  • 56
  • Possible duplicate of [Do I need to explicitly close connection?](https://stackoverflow.com/questions/19938153/do-i-need-to-explicitly-close-connection) – uli Nov 26 '18 at 17:54

1 Answers1

1

The documentation you are referring is for old api. Starting from 3.7 you should use com.mongodb.client.MongoClient and it close() method. New API came with a lot of changes, more details.

uli
  • 671
  • 6
  • 15
  • It puts me one step close, but I'm now having problems to use the com.mongodb.client.MongoClient. I'll update the question – Igor Nov 26 '18 at 19:30
  • Actually, I'll just write here in the comment. I need to parse the com.mongodb.MongoClient to the new com.mongodb.client.MongoClient. That's what I had before: MongoCredential credential = createCredentials(repository); ServerAddress serverAdress = new ServerAddress(repository.getLocation().getHost(), repository.getLocation().getPort()); MongoClientOptions options = MongoClientOptions.builder().serverSelectionTimeout(10000).build(); return new MongoClient(serverAdress, credential, options); – Igor Nov 26 '18 at 19:31
  • How do I properly parse that to the new way? Not being able to figure this out – Igor Nov 26 '18 at 19:32
  • And the link from the answer will help you [more details](http://mongodb.github.io/mongo-java-driver/3.9/driver/getting-started/quick-start/) One of the way `MongoClients.create("mongodb://hostOne:27017,hostTwo:27018")` – uli Nov 26 '18 at 19:49