简体   繁体   English

com.mongodb.client.MongoClient 和 com.mongodb.MongoClient 的区别

[英]Differences between com.mongodb.client.MongoClient and com.mongodb.MongoClient

I'm a bit new in MongoDB and I got confused with MongoClient classes as there are two in different packages ( com.mongodb.client.MongoClient and com.mongodb.MongoClient ).我对 MongoDB 有点陌生,我对 MongoClient 类感到困惑,因为在不同的包中有两个( com.mongodb.client.MongoClientcom.mongodb.MongoClient )。 And what I have seen is that they have more or less the same purpose but I could be wrong.我所看到的是他们或多或少有相同的目的,但我可能是错的。

What are the differences between both classes?两个班级之间有什么区别? Is one of them recommended over the other?是否推荐其中之一?

Use com.mongodb.client.MongoClient.create() (as of 3.7 or later), legacy api com.mongodb.MongoClient() is deprecated.使用com.mongodb.client.MongoClient.create() (从 3.7 或更高版本开始),旧的 api com.mongodb.MongoClient()已弃用。

A com.mongodb.client.MongoClient instance represents a pool of connections to the database; com.mongodb.client.MongoClient实例表示数据库连接池; you will only need one instance of class MongoClient even with multiple threads.即使有多个线程,您也只需要 MongoClient 类的一个实例。

Reference : http://mongodb.github.io/mongo-java-driver/3.12/driver/tutorials/connect-to-mongodb/参考: http : //mongodb.github.io/mongo-java-driver/3.12/driver/tutorials/connect-to-mongodb/

com.mongodb.client.MongoClient is added since 3.7 release use below code to get instance with new API: com.mongodb.client.MongoClient从 3.7 版本开始添加,使用以下代码获取具有新 API 的实例:

    MongoClient mongoClient = MongoClients.create()

暂无
暂无

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

相关问题 Spring MVC无法初始化com.mongodb.MongoClient类 - Spring MVC Could not initialize class com.mongodb.MongoClient 如何使用com.mongodb.MongoClient管理的io.dropwizard.lifecycle.Managed? - How to use io.dropwizard.lifecycle.Managed with com.mongodb.MongoClient? MongoDB Java错误java.lang.NoClassDefFoundError:com / mongodb / MongoClient - MongoDB java error java.lang.NoClassDefFoundError: com/mongodb/MongoClient 我的com.mongoDB jar文件没有mongoClient - My com.mongoDB jar file don't have a mongoClient 错误 java.lang.NoClassDefFoundError: com/mongodb/MongoClient - ERROR java.lang.NoClassDefFoundError: com/mongodb/MongoClient com.mongodb.MongoTimeoutException 使用带有列表 ServerAddress 的 MongoClient 时 - com.mongodb.MongoTimeoutException when using MongoClient with list ServerAddress MongoDB Java驱动程序:线程“ main”中的异常java.lang.NoClassDefFoundError:com / mongodb / MongoClient - MongoDB java driver: Exception in thread “main” java.lang.NoClassDefFoundError: com/mongodb/MongoClient java.lang.NoSuchMethodError:com.mongodb.MongoClient。 <init> (Ljava / UTIL /列表; LCOM / mongodb的/ MongoCredential; LCOM / mongodb的/ MongoClientOptions;)V] - java.lang.NoSuchMethodError: com.mongodb.MongoClient.<init>(Ljava/util/List;Lcom/mongodb/MongoCredential;Lcom/mongodb/MongoClientOptions;)V] 在Java 8中使用MongoDB MongoClient检索一个文档 - Retrieving one document with MongoDB MongoClient in Java 8 Java MongoDB:com.mongodb.DB和com.mongodb.client有什么区别 - Java MongoDB: What is the difference between com.mongodb.DB and com.mongodb.client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM