diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index bf72e70b25..ad70d987bb 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -31,16 +31,16 @@
org.mongodb
mongodb-driver-reactivestreams
- 1.9.2
+ ${mongodb-reactivestreams.version}
-
+
io.projectreactor
reactor-test
- 3.2.0.RELEASE
+ ${projectreactor.version}
test
-
+
org.springframework
spring-core
@@ -106,8 +106,9 @@
2.1.0.RELEASE
4.1.4
1.1.3
- 5.1.0.RELEASE
-
+ 5.1.0.RELEASE
+ 1.9.2
+ 3.2.0.RELEASE
diff --git a/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java b/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java
index 8221d299ed..f1048fa145 100644
--- a/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java
+++ b/spring-data-mongodb/src/main/java/com/baeldung/config/MongoConfig.java
@@ -9,7 +9,7 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.MongoTransactionManager;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
-import org.springframework.data.mongodb.core.convert.CustomConversions;
+import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@@ -50,9 +50,9 @@ public class MongoConfig extends AbstractMongoConfiguration {
}
@Override
- public CustomConversions customConversions() {
+ public MongoCustomConversions customConversions() {
converters.add(new UserWriterConverter());
- return new CustomConversions(converters);
+ return new MongoCustomConversions(converters);
}
@Bean
diff --git a/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java
index bb54a5487f..1da50d7cb4 100644
--- a/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java
+++ b/spring-data-mongodb/src/test/java/com/baeldung/aggregation/ZipsAggregationLiveTest.java
@@ -40,11 +40,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.aggregation.model.StatePopulation;
import com.baeldung.config.MongoConfig;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBObject;
import com.mongodb.MongoClient;
-import com.mongodb.util.JSON;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MongoConfig.class)
@@ -58,23 +56,22 @@ public class ZipsAggregationLiveTest {
@BeforeClass
public static void setupTests() throws Exception {
client = new MongoClient();
- DB testDB = client.getDB("test");
- DBCollection zipsCollection = testDB.getCollection("zips");
+ MongoDatabase testDB = client.getDatabase("test");
+ MongoCollection zipsCollection = testDB.getCollection("zips");
zipsCollection.drop();
InputStream zipsJsonStream = ZipsAggregationLiveTest.class.getResourceAsStream("/zips.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(zipsJsonStream));
reader.lines()
- .forEach(line -> zipsCollection.insert((DBObject) JSON.parse(line)));
+ .forEach(line -> zipsCollection.insertOne(Document.parse(line)));
reader.close();
-
}
@AfterClass
public static void tearDown() throws Exception {
client = new MongoClient();
- DB testDB = client.getDB("test");
- DBCollection zipsCollection = testDB.getCollection("zips");
+ MongoDatabase testDB = client.getDatabase("test");
+ MongoCollection zipsCollection = testDB.getCollection("zips");
zipsCollection.drop();
client.close();
}
diff --git a/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java
index 7befaf8fbd..3a88a1e654 100644
--- a/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java
+++ b/spring-data-mongodb/src/test/java/com/baeldung/gridfs/GridFSLiveTest.java
@@ -205,10 +205,9 @@ public class GridFSLiveTest {
DBObject metaData = new BasicDBObject();
metaData.put("user", "alex");
InputStream inputStream = null;
- String id = "";
try {
inputStream = new FileInputStream("src/main/resources/test.png");
- id = gridFsTemplate.store(inputStream, "test.png", "image/png", metaData).toString();
+ gridFsTemplate.store(inputStream, "test.png", "image/png", metaData).toString();
} catch (FileNotFoundException ex) {
logger.error("File not found", ex);
} finally {
diff --git a/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java
index 7a61f9f98a..d05bde0f1b 100644
--- a/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java
+++ b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/DocumentQueryLiveTest.java
@@ -1,8 +1,11 @@
package com.baeldung.mongotemplate;
-import com.baeldung.config.MongoConfig;
-import com.baeldung.model.EmailAddress;
-import com.baeldung.model.User;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Iterator;
+import java.util.List;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -17,11 +20,9 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import com.baeldung.config.MongoConfig;
+import com.baeldung.model.EmailAddress;
+import com.baeldung.model.User;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MongoConfig.class)
@@ -152,7 +153,7 @@ public class DocumentQueryLiveTest {
user.setAge(35);
mongoTemplate.insert(user);
- final Pageable pageableRequest = new PageRequest(0, 2);
+ final Pageable pageableRequest = PageRequest.of(0, 2);
Query query = new Query();
query.with(pageableRequest);
diff --git a/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java
index ee1d4f4760..fc78921b75 100644
--- a/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java
+++ b/spring-data-mongodb/src/test/java/com/baeldung/mongotemplate/MongoTemplateQueryLiveTest.java
@@ -1,8 +1,11 @@
package com.baeldung.mongotemplate;
-import com.baeldung.config.MongoConfig;
-import com.baeldung.model.EmailAddress;
-import com.baeldung.model.User;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -20,11 +23,9 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
+import com.baeldung.config.MongoConfig;
+import com.baeldung.model.EmailAddress;
+import com.baeldung.model.User;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MongoConfig.class)
@@ -104,7 +105,7 @@ public class MongoTemplateQueryLiveTest {
user.setAge(35);
mongoTemplate.insert(user);
- final Pageable pageableRequest = new PageRequest(0, 2);
+ final Pageable pageableRequest = PageRequest.of(0, 2);
Query query = new Query();
query.with(pageableRequest);
diff --git a/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java
index 3daa58dd19..901610e42d 100644
--- a/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java
+++ b/spring-data-mongodb/src/test/java/com/baeldung/repository/UserRepositoryLiveTest.java
@@ -138,7 +138,7 @@ public class UserRepositoryLiveTest {
user.setName("Adam");
mongoOps.insert(user);
- final Pageable pageableRequest = new PageRequest(0, 1);
+ final Pageable pageableRequest = PageRequest.of(0, 1);
final Page page = userRepository.findAll(pageableRequest);
List users = page.getContent();