In this recipe, we will look at executing the query and insert operations using a Java client for MongoDB. Unlike the Python programming language, Java code snippets cannot be executed from an interactive interpreter. Thus, we will have some unit test cases already implemented; their relevant code snippets will be shown and explained.
For this recipe, we will start a standalone instance. Refer to the Single node installation of MongoDB recipe in Chapter 1, Installing and Starting the MongoDB Server, to learn how to start the server.
The next step is to download the mongo-cookbook-javadriver
Java project from the book's website. This recipe uses a JUnit test case to test various features of the Java client. In this whole process, we will make use of some of the most common API calls and, thus, learn to use them.