Reputation: 129
I'm new using MongoDB, I'm working in a Java project and I started some tutorials to start working with the Driver.
I was using com.mongodb.client
until I noticed that there was no findOne method in the com.mongodb.client.MongoCollection
so I rewrited my project to use only com.mongodb.DB
and the DBCollection
library includes the findOne method which I need.
I was wondering what is the difference between those two libraries?
Thanks!
Upvotes: 4
Views: 4468
Reputation: 42829
com.mongodb.DB
is the old API for accessing Mongo before 3.x. You will find plenty of tutorials for those classes. The code is fully functional and you can use it for accessing Mongo 2.x and Mongo 3.x databases but it is not recommended to start a new project using it.
Since 3.0 the recommended way is via com.mongodb.MongoClient
and com.mongodb.client.MongoDatabase
. See the official tutorial of the Java driver here.
Upvotes: 7