0

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.

2

2 Answers 2

1

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Two answers by different people with the same username ! That's a first for me :)
@Sid I almost left the page thinking I have already answered the question ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.