This blog post presents a simple example showing how to insert a document in mongodb, in the Java language.
The code samples are taken from the Free-Programming-Books-Importer project, available on Github
Use MongoDB Java Driver
Add the java mongo driver to your class path, or if you use maven to the dependencies
in your pom file:
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.2.2</version>
</dependency>
......
</dependencies>
Prepare the Mongo Client
MongoClientURI connectionString = new MongoClientURI("mongodb://codingpedia:codingpedia@localhost:27017/codingpedia-bookmarks");
MongoClient mongoClient = new MongoClient(connectionString);