Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find MongoClient in Java Drivers

In reading all the documentation on the mongo site for using the Java Driver, it makes references to using MongoClient() to make a connection. It talks about how they formerly used Mongo() but it has been deprecated. However, when I download the latest (or any) version of the java driver that the Mongo database links to (http://central.maven.org/maven2/org/mongodb/mongo-java-driver/), and load it into my project libraries, I cannot import com.mongodb.MongoClient because it isn't there! I've tried half a dozen different versions of the driver they link to. I can actually make my program work just fine with the deprecated Mongo(), but I don't want to be building new software on deprecated features. I can't find anyone else with the same problem on here eitherImage of libraries shown in netbeans below, v 2.93 in this case

The above is from version 2.93. Can anyone help me find what I'm doing wrong or missing? I would think its the driver version but these are the links right from Mongo's website. I also don't think its usage error, as I can make everything else work just fine.

like image 598
mikepinch Avatar asked May 11 '13 13:05

mikepinch


People also ask

What is MongoClient in Java?

MongoClient is the interface between our java program and MongoDB server. MongoClient is used to create connection, connect to database, retrieve collection names and create/read/update/delete database, collections, document etc.

How does MongoDB connect to MongoClient in Java?

To connect: MongoClient client = MongoClients. create("<<MongoDB URI>>"); To connect to MongoDB on your local instance and default port, you can just omit the URI part of the above, or use a URI like 'mongodb://localhost:27017'.

How do I instantiate MongoClient?

You can instantiate a MongoClient object without any parameters to connect to a MongoDB instance running on localhost on port 27017 : MongoClient mongoClient = new MongoClient();


1 Answers

I suggest you grab driver version 2.11.3

The JAR contains the MongoClient class that you're referring to. Latter is new to the MongoDB Java driver and has only been included since version 2.10.0 (The version you are referring to is 2.9.3, as of now the latest driver version is the aforementioned 2.11.3)

Cheers ;)

like image 198
codesurgeon Avatar answered Oct 12 '22 11:10

codesurgeon