diff --git a/persistence-modules/java-mongodb-3/.gitignore b/persistence-modules/java-mongodb-3/.gitignore
new file mode 100644
index 0000000000..79ba317cb5
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/.gitignore
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+build
\ No newline at end of file
diff --git a/persistence-modules/java-mongodb-3/pom.xml b/persistence-modules/java-mongodb-3/pom.xml
new file mode 100644
index 0000000000..6b02172491
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+ java-mongodb-3
+ 1.0-SNAPSHOT
+ java-mongodb-3
+
+
+ com.baeldung
+ persistence-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.mongodb
+ mongo-java-driver
+ ${mongo.version}
+
+
+
+
+ 3.12.1
+
+
+
diff --git a/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindOperation.java b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindOperation.java
new file mode 100644
index 0000000000..6000684deb
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindOperation.java
@@ -0,0 +1,86 @@
+package com.baeldung.mongo.find;
+
+import com.mongodb.MongoClient;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
+
+public class FindOperation {
+
+ private static MongoClient mongoClient;
+ private static MongoDatabase database;
+ private static MongoCollection collection;
+ private static String collectionName;
+ private static String databaseName;
+
+ public static void setUp() {
+ if (mongoClient == null) {
+ mongoClient = new MongoClient("localhost", 27017);
+
+ databaseName = "baeldung";
+ collectionName = "employee";
+
+ database = mongoClient.getDatabase(databaseName);
+ collection = database.getCollection(collectionName);
+ }
+ }
+
+ public static void retrieveAllDocumentsUsingFind() {
+ FindIterable documents = collection.find();
+
+ MongoCursor cursor = documents.iterator();
+ while (cursor.hasNext()) {
+ System.out.println(cursor.next());
+ }
+ }
+
+ public static void retrieveAllDocumentsUsingFindWithQueryFilter() {
+ Bson filter = eq("department", "Engineering");
+ FindIterable documents = collection.find(filter);
+
+ MongoCursor cursor = documents.iterator();
+ while (cursor.hasNext()) {
+ System.out.println(cursor.next());
+ }
+ }
+
+ public static void retrieveAllDocumentsUsingFindWithQueryFilterAndProjection() {
+ Bson filter = eq("department", "Engineering");
+ Bson projection = fields(include("name", "age"));
+ FindIterable documents = collection.find(filter)
+ .projection(projection);
+
+ MongoCursor cursor = documents.iterator();
+ while (cursor.hasNext()) {
+ System.out.println(cursor.next());
+ }
+ }
+
+ public static void retrieveFirstDocument() {
+ FindIterable documents = collection.find();
+ Document document = documents.first();
+
+ System.out.println(document);
+ }
+
+ public static void main(String args[]) {
+
+ setUp();
+
+ retrieveAllDocumentsUsingFind();
+
+ retrieveAllDocumentsUsingFindWithQueryFilter();
+
+ retrieveAllDocumentsUsingFindWithQueryFilterAndProjection();
+
+ retrieveFirstDocument();
+ }
+}
+
diff --git a/persistence-modules/java-mongodb-3/src/main/resources/logback.xml b/persistence-modules/java-mongodb-3/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindOperationLiveTest.java b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindOperationLiveTest.java
new file mode 100644
index 0000000000..21a263381d
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindOperationLiveTest.java
@@ -0,0 +1,94 @@
+package com.baeldung.mongo.find;
+
+import com.mongodb.MongoClient;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
+import static org.junit.Assert.*;
+
+public class FindOperationLiveTest {
+
+ private static MongoClient mongoClient;
+ private static MongoDatabase database;
+ private static MongoCollection collection;
+ private static final String DATASET_JSON = "/employee.json";
+
+ @BeforeClass
+ public static void setUp() throws IOException {
+ if (mongoClient == null) {
+ mongoClient = new MongoClient("localhost", 27017);
+
+ database = mongoClient.getDatabase("baeldung");
+ collection = database.getCollection("employee");
+
+ collection.drop();
+
+ InputStream is = FindOperationLiveTest.class.getResourceAsStream(DATASET_JSON);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ reader.lines()
+ .forEach(line -> collection.insertOne(Document.parse(line)));
+ reader.close();
+ }
+ }
+
+ @Test
+ public void givenEmployeeCollection_whenFetchingUsingFindOperations_thenCheckingForDocuments() {
+ FindIterable documents = collection.find();
+ MongoCursor cursor = documents.iterator();
+
+ assertNotNull(cursor);
+ assertTrue(cursor.hasNext());
+ }
+
+ @Test
+ public void givenEmployeeCollection_whenFetchingUsingFindOperationsWithFilters_thenCheckingForDocuments() {
+ Bson filter = eq("department", "Engineering");
+ FindIterable documents = collection.find(filter);
+ MongoCursor cursor = documents.iterator();
+
+ assertNotNull(cursor);
+ assertTrue(cursor.hasNext());
+ }
+
+ @Test
+ public void givenEmployeeCollection_whenFetchingUsingFindOperationsWithFiltersAndProjection_thenCheckingForDocuments() {
+ Bson filter = eq("department", "Engineering");
+ Bson projection = fields(include("name", "age"));
+ FindIterable documents = collection.find(filter)
+ .projection(projection);
+ MongoCursor cursor = documents.iterator();
+
+ assertNotNull(cursor);
+ assertTrue(cursor.hasNext());
+ }
+
+ @Test
+ public void givenEmployeeCollection_whenFetchingFirstDocumentUsingFindOperations_thenCheckingForDocument() {
+ Document employee = collection.find()
+ .first();
+
+ assertNotNull(employee);
+ assertFalse(employee.isEmpty());
+ }
+
+ @AfterClass
+ public static void cleanUp() {
+ mongoClient.close();
+ }
+}
+
diff --git a/persistence-modules/java-mongodb-3/src/test/resources/employee.json b/persistence-modules/java-mongodb-3/src/test/resources/employee.json
new file mode 100644
index 0000000000..bcc7814c3b
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/src/test/resources/employee.json
@@ -0,0 +1,3 @@
+{"employeeId":"EMP1","name":"Sam","age":23,"type":"Full Time","department":"Engineering"}
+{"employeeId":"EMP2","name":"Tony","age":31,"type":"Full Time","department":"Admin"}
+{"employeeId":"EMP3","name":"Lisa","age":42,"type":"Part Time","department":"Engineering"}
\ No newline at end of file
diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml
index 4637ab7ecc..4bab0631bd 100644
--- a/persistence-modules/pom.xml
+++ b/persistence-modules/pom.xml
@@ -44,6 +44,7 @@
java-jpa-3
java-mongodb
java-mongodb-2
+ java-mongodb-3
jnosql
jooq
jpa-hibernate-cascade-type