简体   繁体   English

MongoDB和Apache Mahout连接错误

[英]MongoDB and Apache Mahout Connection Error

Trying to Connect Apache Mahout to a Mongo DB. 尝试将Apache Mahout连接到Mongo数据库。 However when I run it I get the following error. 但是,当我运行它时,出现以下错误。 Not Sure what's wrong. 不知道怎么了。 I have Also made sure that the MongoClient Library connects. 我还确保MongoClient库连接。

Error: 错误:

java.lang.NoSuchMethodError: com.mongodb.DBCollection.ensureIndex(Lcom/mongodb/DBObject;)V

    at org.apache.mahout.cf.taste.impl.model.mongodb.MongoDBDataModel.buildModel(MongoDBDataModel.java:559)
    at org.apache.mahout.cf.taste.impl.model.mongodb.MongoDBDataModel.<init>(MongoDBDataModel.java:243)
    at util.Connection.connectToServer(Connection.java:23)

Method: 方法:

public MongoDatabase connectToServer() throws MongoSocketException, UnknownHostException {


        //Working
        MongoClientURI uri = new MongoClientURI("mongodb://localhost:27017");

            MongoClient mongoDB = new MongoClient(uri);
            MongoDatabase mongoConnection = mongoDB.getDatabase("loka");

        //Throws Error
            MongoDBDataModel dbm = new MongoDBDataModel("127.0.0.1",27017,"loka","BEACON_LOOKUP",true,false,null);

            return mongoConnection;
    }

POM Dependancies: POM依赖关系:

<dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-core</artifactId>
            <version>0.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-math</artifactId>
            <version>0.12.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-collections</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-integration</artifactId>
            <version>0.12.2</version>
        </dependency>

I'm no expert of Mahout nor Java. 我既不是Mahout也不是Java的专家。 But the error message does look like you are using an incompatible version of MongoDB Java Driver. 但是错误消息的确看起来像您使用的是MongoDB Java驱动程序的不兼容版本。

Note that there are 2 branches of MongoDB Java Driver: 请注意,MongoDB Java驱动程序有2个分支:

  1. 2.x maintains old driver from before. 2.x从以前维护旧驱动程序。
  2. To support async and new MongoDB features there's 3.x branch. 为了支持异步和新的MongoDB功能,有3.x分支。

The 3.x branch is not backward compatible. 3.x分支不向后兼容。 Methods like ensureIndex are changed to createIndex for example. 例如,将诸如ensureIndex类的方法更改为createIndex There are bunch of other changes too. 还有很多其他变化。 So back to your question, I think you should try latest 2.x branch, which is 2.14 by now. 回到您的问题,我想您应该尝试使用最新的2.x分支,即目前的2.14。

To check compatibility between Java Driver and MongoDB version, read the document . 要检查Java驱动程序和MongoDB版本之间的兼容性,请阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM