[英]Java MongoDB: What is the difference between com.mongodb.DB and com.mongodb.client
I'm new using MongoDB, I'm working in a Java project and I started some tutorials to start working with the Driver. 我是使用MongoDB的新手,正在从事Java项目,并且开始了一些教程来开始使用Driver。
I was using com.mongodb.client
until I noticed that there was no findOne method in the com.mongodb.client.MongoCollection
so I rewrited my project to use only com.mongodb.DB
and the DBCollection
library includes the findOne method which I need. 我用
com.mongodb.client
直到我注意到,有一个在没有findOne方法com.mongodb.client.MongoCollection
所以我rewrited我的项目只使用com.mongodb.DB
和DBCollection
库包括findOne方法,我需要。
I was wondering what is the difference between those two libraries? 我想知道这两个库有什么区别?
Thanks! 谢谢!
com.mongodb.DB
is the old API for accessing Mongo before 3.x. com.mongodb.DB
是用于在3.x之前访问Mongo的旧API。 You will find plenty of tutorials for those classes. 您将找到大量关于这些课程的教程。 The code is fully functional and you can use it for accessing Mongo 2.x and Mongo 3.x databases but it is not recommended to start a new project using it.
该代码具有完整的功能,您可以将其用于访问Mongo 2.x和Mongo 3.x数据库,但是不建议您使用它来启动新项目。
Since 3.0 the recommended way is via com.mongodb.MongoClient
and com.mongodb.client.MongoDatabase
. 从3.0开始,推荐的方式是通过
com.mongodb.MongoClient
和com.mongodb.client.MongoDatabase
。 See the official tutorial of the Java driver here . 在此处查看Java驱动程序的官方教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.