Prerequisites
Prerequisites
To build and run this project, you will need IntelliJ IDEA Community Edition for MacOS, Windows, or Linux. You can download it here.
A working installation of the Java 8 JDK.
A working installation of the Maven build system. (Your IntelliJ installation should include this)
It is also helpful, but not necessary, to have a working installation of Git version control.
Some of these tools may come pre-installed in your programming environment.
1. Download the Repository
To get started with this sample project, download this repository to your programming environment. You can either download this project using Git version control:
git clone git@github.com:mongodb-university/atlas_starter_java.git
Or you can download a ZIP archive using your browser from GitHub. If you download this project as a ZIP archive, unzip the archive before proceeding.
2. Open the Project
In IntelliJ, select
File > Open...
Navigate to the directory containing this project.
Select the directory
atlas_starter_java
.Click
OK
.
3. Configure Maven
In IntelliJ, click to expand the
atlas_starter_java
directory.Right click on the directory named
src
.Select
Mark Directory as
from the context menu.Select
Sources Root
.
4. Configure your Atlas Credentials
Expand
atlas_starter_java > src > main > java > mongodb > Main
.Double-click
Main
.On the following lines in
Main
, replace the Atlas connection URI with your own from the Atlas UI.
// TODO: // Replace the placeholder connection string below with your // Altas cluster specifics. Be sure it includes // a valid username and password! Note that in a production environment, // you do not want to store your password in plain-text here. String mongoUri = "<Your Atlas Connection String>";
5. Run the Project
Right click
Main
.Select
Run 'Main.main()'
from the context menu.
Congratulations! You have just connected to MongoDB Atlas using the Java MongoDB Driver! Try modifying the code to experiment with the Driver and MongoDB!