Reputation: 766
I'm trying to write a program in Java that will connect to a MongoDB database. I already have the server, port, name, userDB, and username/password of the MongoDB database I'm trying to access.
I wasn't really sure where to start, so after looking around for a bit, I found a Java driver for MongoDB available on GitHub: https://github.com/mongodb/mongo-java-driver. I downloaded the source code and imported it as a project on Eclipse. The source code for the driver has literally hundreds if not thousands of files. I tried running it as is, and couldn't get the project to compile.
I have no clue where to go from here. There isn't a lot of in-depth instructional material out there for this, and if I took the time to thoroughly inspect all the files in the driver, that could take decades.
Upvotes: 0
Views: 550
Reputation: 7631
Download the .JAR file from here: https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.0.0/
You need mongodb-driver-3.0.0.jar from this list.
Once you have that add it as a library dependency in your Eclipse project and you'll be all set.
Upvotes: 0
Reputation: 463
You are on the right track here. What you need to do instead of downloading the source code is to download the JAR files or alternatively use Maven which is a dependency management tool.
This is what you will need to install the mongodb driver. After you have successfully added the dependencies to your project. Use this quick start guide which will step you through the basics.
Here is an example of working with maven.
Don't get disheartened by small trials..there's always decades of documentation to read ;)
Upvotes: 1