Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

710
Visualizações
mongodb Java Driver build error : cannot access com.mongodb.client.result.InsertOneResult, class file not found

I'm following the Installation and Quick Start on the latest (4.2.2) Mongodb Java drivers. I'm getting this compile error:

Error:(29, 29) java: cannot access com.mongodb.client.result.InsertOneResult class file for com.mongodb.client.result.InsertOneResult not found

This is part of a larger project, so could there be another version of mongo somewhere on the class path?
There is only one the pom, and it is this, straight from the Installation page:

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

I'm using IntelliJ, and in it's External Dependencies for mongo, it has these:

org.mongodb:bson:3.8.2
org.mongodb:mongodb-driver-core:3.8.2
org.mongodb:mongodb-driver-sync:4.2.2

Here's the code :

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.Arrays;

public class MongoTest {

    public static void main(String[] args) {
        MongoTest mongoTest = new MongoTest();
        mongoTest.init();
    }

    public void init() {
        MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017");
        MongoDatabase myTestDb = mongoClient.getDatabase("myTestDb");
        MongoCollection<Document> collection = myTestDb.getCollection("test");

        Document doc = new Document("name", "MongoDB")
                .append("type", "database")
                .append("count", 1)
                .append("versions", Arrays.asList("v3.2", "v3.0", "v2.6"))
                .append("info", new Document("x", 203).append("y", 102));

        collection.insertOne(doc);
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need all three dependencies, but they should all be the same version, e.g.

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

If you take a dependency only on mongodb-driver-sync, the others should be picked up transitively. But it sounds like there is a conflict somewhere which is causing you to pick up older versions of bson and mongodb-driver-core. You will need to determine where that conflict is coming from and address it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda