[JAVA-4810] In Java sync driver 4.7.1, collection.drop() does not work. Got NoClassDefFoundError for com/mongodb/client/model/DropCollectionOptions Created: 13/Nov/22  Updated: 14/Nov/22  Resolved: 14/Nov/22

Status: Closed
Project: Java Driver
Component/s: Build
Affects Version/s: 4.7.1
Fix Version/s: None

Type: Question Priority: Minor - P4
Reporter: Rafiul Ahad Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File my-app.tar    

 Description   

Summary

collection.drop does not work. Got NoClassDefFoundError for com/mongodb/client/model/DropCollectionOptions 

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

How to Reproduce

MongoCollection<Document> collection = db.getCollection("test");
collection.drop();

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Rafiul Ahad [ 14/Nov/22 ]

I forgot to mention that my app is a Spring Boot app. After I did mvn clean install, it seemed to have resolved the issue.

Thank you.

-Rafiul

Comment by Jeffrey Yemin [ 14/Nov/22 ]

I attached my-app.tar that demonstrates what I mean by a minimal reproducible example in the context of your issue. Download it, extract the contents, and run the following command: mvn compile exec:java -Dexec.mainClass="com.mongodb.test.App" and it should print:

1
0

This example demonstrates that with a simple pom.xml that depends on mongodb-driver-sync:4.7.1, your code sample works as expected.

Please provide a similar example that demonstrates the exception you are experiencing. Otherwise, I'm going to close this issue as unreproducible.

Regards,
Jeff

Comment by Rafiul Ahad [ 14/Nov/22 ]

public void dropCollection(MongoDatabase db, String collName)

{ MongoCollection<Document> collection = db.getCollection(collName); collection.drop(); }
Comment by Jeffrey Yemin [ 14/Nov/22 ]

The mongodb-driver-sync pom shows pretty clearly the dependencies are correct, so I can't explain what you're seeing without more information.

Please post a minimal reproducible example so we can investigate further.

Comment by Rafiul Ahad [ 14/Nov/22 ]

 +- org.mongodb:mongodb-driver-sync:jar:4.7.1:compile

[{*}INFO{*}] |  +- org.mongodb:bson:jar:4.6.1:compile

[{*}INFO{*}] |  - org.mongodb:mongodb-driver-core:jar:4.6.1:compile

[{*}INFO{*}] |     - org.mongodb:bson-record-codec:jar:4.6.1:runtime

Comment by Jeffrey Yemin [ 14/Nov/22 ]

rafiulahad@gmail.com it's unlikely that this is a bug given how many applications are running on 4.7.

Can you run the command mvn dependency:tree and post the output in a comment? My hypothesis is that it will uncover a dependency conflict.

Comment by Rafiul Ahad [ 13/Nov/22 ]

Maven shows that 4.7.1 has 4.6.1 version of core and bson. 

Comment by Jeffrey Yemin [ 13/Nov/22 ]

It should be, so something else must be going on. Check if some other dependency is pinning mongodb-driver-core to an older version (DropCollectionOptions was only introduced in mongodb-driver-core:4.7.0).

Comment by Rafiul Ahad [ 13/Nov/22 ]

I currently have the following dependency in my pom.xml. Is that not enough?

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.7.1</version>
</dependency>

Comment by Jeffrey Yemin [ 13/Nov/22 ]

Please double-check that org.mongodb:mongodb-driver-core:4.7.1 and org.mongodb:bson:4.7.1 are also in your classpath.

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