在 Java 驱动程序中找不到 MongoClient
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16497799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't find MongoClient in Java Drivers
提问by mikepinch
In reading all the documentation on the mongo site for using the Java Driver, it makes references to using MongoClient() to make a connection. It talks about how they formerly used Mongo() but it has been deprecated. However, when I download the latest (or any) version of the java driver that the Mongo database links to (http://central.maven.org/maven2/org/mongodb/mongo-java-driver/), and load it into my project libraries, I cannot import com.mongodb.MongoClient because it isn't there! I've tried half a dozen different versions of the driver they link to. I can actually make my program work just fine with the deprecated Mongo(), but I don't want to be building new software on deprecated features. I can't find anyone else with the same problem on here either
在阅读 mongo 站点上有关使用 Java 驱动程序的所有文档时,它提到了使用 MongoClient() 建立连接。它讲述了他们以前如何使用 Mongo() 但它已被弃用。但是,当我下载 Mongo 数据库链接到的最新(或任何)版本的 Java 驱动程序时(http://central.maven.org/maven2/org/mongodb/mongo-java-driver/),并加载它到我的项目库中,我无法导入 com.mongodb.MongoClient 因为它不存在!我已经尝试了他们链接到的六个不同版本的驱动程序。实际上,我可以使用已弃用的 Mongo() 使我的程序正常工作,但我不想在已弃用的功能上构建新软件。我在这里也找不到其他有同样问题的人
The above is from version 2.93. Can anyone help me find what I'm doing wrong or missing? I would think its the driver version but these are the links right from Mongo's website. I also don't think its usage error, as I can make everything else work just fine.
以上来自2.93版。谁能帮我找出我做错了什么或遗漏了什么?我认为它是驱动程序版本,但这些是来自 Mongo 网站的链接。我也不认为它的使用错误,因为我可以让其他一切正常工作。
回答by codesurgeon
I suggest you grab driver version 2.11.3
建议你抓驱动版本2.11.3
The JAR contains the MongoClient
class that you're referring to. Latter is new to the MongoDB Java driver and has only been included since version 2.10.0 (The version you are referring to is 2.9.3, as of now the latest driver version is the aforementioned 2.11.3)
JAR 包含MongoClient
您所指的类。后者是 MongoDB Java 驱动程序的新内容,仅从 2.10.0 版开始包含(您所指的版本是 2.9.3,截至目前最新的驱动程序版本是上述 2.11.3)
Cheers ;)
干杯;)