The Java driver is the oldest MongoDB driver. It has been used in production for years and is stable and a popular choice for enterprise developers.
We’ll be using the Java driver to build a search engine for chemical compounds, heavily inspired by http://www.chemeo.com. This search engine has the chemical and physical properties of thousands of compounds on file, and its goal is to make this information fully searchable.
The Java driver comes as a JAR file that can be downloaded from Github. To install, add the JAR to your classpath.
All of the Java classes you will probably need to use in a normal
application are in the
com.mongodb.gridfs packages. There are a number of
other packages included in the .JAR that are useful if you are planning
on manipulating the driver’s internals or expanding its functionality,
but most applications can ignore them.
Like most things in Java, the API is a bit verbose (especially compared to the other languages’ APIs). However, all of the concepts are similar to using the shell, and almost all of the method names are identical.
com.mongodb.Mongo class creates a connection to a MongoDB server. You can access a database from the connection and then get ...