NoSuchMethodError exception

Hi team,
I’m currently working on using mongodb-driver 4.x in my project and I received the following exception when I run the service.

Caused by: java.lang.NoSuchMethodError: com.mongodb.internal.operation.SyncOperations.find(Lorg/bson/conversions/Bson;Ljava/lang/Class;Lcom/mongodb/internal/client/model/FindOptions;)Lcom/mongodb/internal/operation/ReadOperation;

The specific line I’m executing is:

getCollection().find(...).into(new ArrayList<>());

The parameter I passed in find() method is of type Bson, imported as “import org.bson.conversions.Bson;”

There’s a similar post about this issue java.lang.noSuchMethodError with .iterator or .into when using .find. I added those depedencies in my config file as well but with no luck to resolve this problem.

Config file:
depedencies {
  1.0 = {
     ...
    Maven-org-mongodb_mongodb-driver-sync = 4.x;
    Maven-org-mongodb_mongodb-driver-core = 4.x;
    Maven-org-mongodb_bson = 4.x;
    ...
  }
}

Any suggestion or direction for me to move forward?
Thank you very much!!

Hello @Yilin_Liu, welcome to the MongoDB Community forum!

As per the MongoDB Java Driver v4.x your code should work (I tried something similar using Java SE 8 and MongoDB v4.2.x):

MongoCollection<Document> coll = client.getDatabase("test")
                                       .getCollection("books");
List<Document> docs = coll.find(new Document("author", "Mark Twain"))
                          .into(new ArrayList<>());

My Maven dependency:

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

Also refer MongoDB Java Driver Read Operations