Eclipse中的MongoDB Java驱动程序错误

时间:2016-02-01 11:12:56

标签: eclipse mongodb mongodb-java

我已经整理了一个简单的程序,它连接到正在运行的MongoDB实例,获取现有的数据库和集合(之前创建的)并插入文档。它看起来像这样:

    public class MyClass {

        public void main(String args[]) {

        try {
             MongoClient client = new MongoClient("localhost", 27017);
             String connectionPoint = client.getConnectPoint();

             DB db = (DB) client.getDatabase("aDb");
             DBCollection collection = db.getCollection("aCollection");

             BasicDBObject document = new BasicDBObject();
             document.put("name", "james");
             collection.insert(document);
             client.close();

            } catch (MongoException e) {
                e.printStackTrace();
        }
    }
}
但是,当我在Eclipse中将其作为Java应用程序运行时,我返回时带有以下消息:

Usage : [--bucket bucketname] action
  where  action is one of:
      list                      : lists all files in the store
      put filename              : puts the file filename into the store
      get filename1 filename2   : gets filename1 from store and sends to filename2
      md5 filename              : does an md5 hash on a file in the db (for testing)

我不确定这意味着什么,我一直在努力寻找任何真正的解决方案(MongoDB - eclipse)。我的引用库包括mongo-java-driver-3.2.1.jar(其中com.mongodb.client.gridfs是其中的一部分)和bson-3.2.1.jar以及我的MongoDB实例正确运行。我错过了什么真的很明显吗?

非常感谢任何帮助!

谢谢!

修改

小应用程序的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>MongoConnection</groupId>
  <artifactId>MongoConnection</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
            <version>3.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>bson</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>
</project>

0 个答案:

没有答案