[JAVA-3842] Mac os can connect to remotely Mongo 4.2.9 while Ubuntu can't Created: 14/Sep/20  Updated: 15/Sep/20  Resolved: 15/Sep/20

Status: Closed
Project: Java Driver
Component/s: Configuration
Affects Version/s: 4.1.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Mohammad Amr Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac os -> Catalina 10.150.6
Ubuntu os -> 20.04.1 LTS Focal


Attachments: PNG File image (1).png     PNG File image.png    
Issue Links:
Documented
Documentation Changes: Needed

 Description   

When I connect my Java Project using the below maven dependencies to Mongo 4.2.9 that was hosted remotely, If I'm using Macos, it will connects successfully.

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.3.RELEASE</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-core</artifactId>
			<version>4.1.0</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-sync</artifactId>
			<version>4.0.1</version>
		</dependency>

When I was using Ubuntu, it will fail with the below exception:

java.lang.NoSuchMethodError: 'java.lang.String com.mongodb.connection.ClusterSettings.getDescription()'

But If I changed the dependencies to be like below:

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.1.RELEASE</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-core</artifactId>
			<version>4.0.4</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-sync</artifactId>
			<version>4.0.4</version>
		</dependency>

It will fail to connect to Mongo 4.2.9 even on Mac or Ubuntu.

 

The error on Mac is:

nested exception is java.lang.NoSuchMethodError: 'java.lang.String com.mongodb.connection.ClusterSettings.getDescription()'

while the error on Ubuntu is:

nested exception is java.lang.NoSuchMethodError: 'void com.mongodb.internal.connection.DefaultClusterableServerFactory.<init>(..)

 



 Comments   
Comment by Jeffrey Yemin [ 15/Sep/20 ]

mohammad.amr@baaz.com

Glad you figured it out.

Comment by Mohammad Amr [ 15/Sep/20 ]

Dears, the issue has been resolved, it's a mixture of having the valid dependency and removing all old versions from all libraries. Thanks alot for your efforts. I discovered that once I created the Minimal Reproducible project. Nice technique.

 

Issue closed.

 
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>3.0.3.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>bson</artifactId>
    <version>4.0.1</version>
</dependency>

Comment by Mohammad Amr [ 15/Sep/20 ]

@Jeffrey Yemin, 

I'm preparing this for you

Comment by Jeffrey Yemin [ 15/Sep/20 ]

mohammad.amr@baaz.com

I concur with cstrobl. We need a Minimal Reproducible Example in order to assist you further.

Comment by Mohammad Amr [ 15/Sep/20 ]

I update my maven files to just contain these below dependencies that are relevant for mongo

 

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.3.RELEASE</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-sync</artifactId>
			<version>4.0.1</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>bson</artifactId>
			<version>4.0.1</version>
		</dependency>

The result, it works for Macos but not for ubuntu. with the same error shown here

I'm working on your notes below:

"

Different OS are also likely to resolve dependencies and load classes in different order, so the issue might also be that there's an old version of the driver somewhere on the path that gets loaded on Ubuntu and not on MacOS.

Minimal Reproducible Example would help spot the issue."

Comment by Christoph Strobl [ 15/Sep/20 ]

Spring Data MongoDB (sync) requires the following dependencies:

  • org.mongodb:mongodb-driver-core
  • org.mongodb:mongodb-driver-sync

Please do not use mongodb-driver-legacy.

Different OS are also likely to resolve dependencies and load classes in different order, so the issue might also be that there's an old version of the driver somewhere on the path that gets loaded on Ubuntu and not on MacOS.

A Minimal Reproducible Example would help spot the issue.

Comment by Mohammad Amr [ 15/Sep/20 ]

Even though I have used just 

 

<dependency>			
<groupId>org.springframework.data</groupId>			
<artifactId>spring-data-mongodb</artifactId>			
<version>3.0.3.RELEASE</version>	// Use this or any version you want the same result.				
</dependency>

But unfortunately, still it's not working for ubuntu even if I have included some additional libraries like spring-commons. See 

Comment by Mohammad Amr [ 15/Sep/20 ]

I traced all libraries that should be there, I found that even I removed mongo-java-driver.3.12.7, the application will keep running on Macos but for ubuntu nothing changed.

 

This is the last configuration I made, it's working on Macos but doesn't on Ubuntu.

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.3.RELEASE</version>			
		</dependency>
 
 
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-legacy</artifactId>
			<version>4.0.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.mongodb</groupId>
					<artifactId>mongo-java-driver</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

Comment by Mohammad Amr [ 14/Sep/20 ]

Dears,

Let me update you about the MongoDB 4 upgrade that Pas 3.2.6 is fully
working on Macos when it is connecting to remote MongoDB 4.2.9.
Unfortunately, Pas 3.2.6 isn't able to connect to Mongo DB 4 either it is
located locally or remotely especially when Pas is working on Ubuntu
20.04.1 LTS or that machine that Majd has constructed.

I'm doing all that I can to solve this issue as soon as possible and I
tried many ways to get over this with no avail. Such behavior is very
strange , so I opened a ticket with the MongoDB team to help solve this
issue. The URL of this ticket is already attached.

Action Plan:

  • I will prepare Pas 3.2.6 to be able to work on MongoDB 3.x until this
    issue is resolved.

On Tue, Sep 15, 2020 at 12:29 AM Jeffrey Yemin (Jira) <jira@mongodb.org>

___ _

Mohammad Amr

Sr.Software Engineer - Java/Python

Address: Emaar Towers - Amman, Jordan.

Mob: +962 7 8873 1763

www.baaz.com

Comment by Mohammad Amr [ 14/Sep/20 ]

If I were only using Spring-Data Dependency as below:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>2.2.9.RELEASE</version>
</dependency>

my app would have connected to my localhost database not the remote one which means that it ignores all spring.xml entries I made.

 

It's so strange and I'm stuck here. Please advise me.

Comment by Mohammad Amr [ 14/Sep/20 ]

If I were only using Spring-Data dependency, I would have received an exception like:

 

Error creating bean with name 'mongo': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: 'java.lang.String com.mongodb.connection.ClusterSettings.getDescription()'

Comment by Mohammad Amr [ 14/Sep/20 ]

I'm just using these two lines:

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.3.RELEASE</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-legacy</artifactId>
			<version>4.0.0</version>
		</dependency>

It works for Macos, but not for Ubuntu. Note: JDK is 14

Comment by Jeffrey Yemin [ 14/Sep/20 ]

Yes, that's what I mean. I'm surprised that depending just on spring-data-mongodb is not sufficient.

Comment by Mohammad Amr [ 14/Sep/20 ]

Do you mean that only all what I have to use are these below:

 

		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>3.0.3.RELEASE</version>
		</dependency>
 
 
		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongodb-driver-legacy</artifactId>
			<version>4.0.0</version>
		</dependency>

I removed everything except these two lines above and still I have the same issue. It's working on Macos but on ubuntu it doesn't.

Comment by Mohammad Amr [ 14/Sep/20 ]

I have this maven dependency somewhere

 

		<dependency>
			<groupId>org.mongodb</groupId>
			<artifactId>mongo-java-driver</artifactId>
			<version>3.12.7</version>
		</dependency>

Do you mean this invalid !!

Comment by Jeffrey Yemin [ 14/Sep/20 ]

These were methods that were deprecated in a 3.x release of the driver and removed in 4.0.0. The only way I can see this happening is if somehow you are picking up a 3.x driver artifact. Can you check for that possibility?

cstrobl any ideas on your end?

Generated at Thu Feb 08 09:00:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.