Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade mongo db to 3.2 in spring boot application

I am using spring boot 1.2.8 with Mongo db 2.4.10. I am planning to upgrade mongo db to 3.2.0.

So with current sprinb boot 1.2.8 i use below in pom,

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

I see in the dependency hierarchy it comes with mongo-java-driver version 2.12.5

But i read in mongo java driver doc, it says even with version 2.14, it does not support all MongoDB 3.2 features (e.g., read concern)

So i upgrade spring boot to the latest version of 1.3.3 expecting i would get a mongo-java-driver version 3.2 which support all mongo db 3.2 features.

But i get mongo-java-driver 2.13.3 with Springboot 1.3.3

So how can i upgrade my application to support mongo db version 3.2?

Edit:

With the latest spring boot 1.3.4 below is the hierarchy,

spring-boot-starter-data-mongodb 1.3.4 [compile]
    -mongo-java-driver 2.13.3 [compile]
        -spring-data-mongodb 1.8.4 [compile]
              -mongo-java-driver 2.13.3 [omitted for conflict with 2.13.3]

The ref doc says, What’s new in Spring Data MongoDB 1.9=>Assert compatibility with MongoDB 3.0 and MongoDB Java Driver 3.2

What’s new in Spring Data MongoDB 1.7=>Assert compatibility with MongoDB 3.0 and MongoDB Java Driver 3-beta3

So is it correct to say, if i use spring boot 1.3.4 with just above mentioned spring boot 1.3.4, it will support all features of mongo db 3.2, although i get spring-data-mongodb 1.8.4?

like image 214
Harshana Avatar asked May 06 '16 16:05

Harshana


People also ask

Does spring spring support MongoDB?

Spring also provides connectors like MongoTemplate and MongoRepository to perform all the database operations in MongoDB. What is Spring Boot used for? Spring Boot framework is used to create production-ready web applications with default configurations.

How do I upgrade to a different version of MongoDB?

You can upgrade from MongoDB 3.0 to 3.2 using a "rolling" upgrade to minimize downtime by upgrading the members individually while the other members are available: Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.

What is Mongo repository in Spring Boot?

MongoRepository — MongoRepository is used for basic queries that involve all or many fields of the document. Examples include data creation, viewing documents, and more. Spring Boot MongoDB configuration using both approaches needs only a few lines of code. Spring is an application framework for Java web applications.

How do I access data from MongoDB Atlas cluster using spring data?

We use Spring Data MongoDB dependency to access the data from our MongoDB Atlas cluster in this application. Enter the project metadata (as shown in the image above) and select the JAR option. Using Spring Initializr takes care of creating a pom.xml file.


1 Answers

Spring Data MongoDB builds on top of MongoDB's Java driver. It uses it to communicate with a MongoDB instance. To use Spring Data MongoDB you need both it and the Java driver.

Spring Data MongoDB support the 3.x driver. To use it you can override the driver's version that's configured by Spring Boot by adding the following to your pom:

<properties>
    <mongodb.version>3.2.2</mongodb.version>
</properties>
like image 149
Andy Wilkinson Avatar answered Oct 28 '22 03:10

Andy Wilkinson