Java MongoDB:com.mongodb.DB和com.mongodb.client之间有什么区别 [英] Java MongoDB: What is the difference between com.mongodb.DB and com.mongodb.client

查看:765
本文介绍了Java MongoDB:com.mongodb.DB和com.mongodb.client之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用MongoDB的新手,我正在Java项目中工作,我开始使用一些教程来开始使用Driver。

I'm new using MongoDB, I'm working in a Java project and I started some tutorials to start working with the Driver.

我使用的是 com.mongodb.client 直到我注意到 com.mongodb.client.MongoCollection 中没有findOne方法所以我重写了我的项目只使用 com.mongodb.DB DBCollection 库包含我需要的findOne方法。

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.

我想知道这两个库有什么区别?

I was wondering what is the difference between those two libraries?

谢谢!

推荐答案

com.mongodb.DB 是在3.x之前访问Mongo的旧API。你会发现很多这些课程的教程。代码功能齐全,您可以使用它来访问Mongo 2.x和Mongo 3.x数据库,但不建议使用它来启动新项目。

com.mongodb.DB is the old API for accessing Mongo before 3.x. 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.

从3.0开始,推荐的方法是通过 com.mongodb.MongoClient com.mongodb.client.MongoDatabase 。请参阅此处Java驱动程序的官方教程

Since 3.0 the recommended way is via com.mongodb.MongoClient and com.mongodb.client.MongoDatabase. See the official tutorial of the Java driver here.

这篇关于Java MongoDB:com.mongodb.DB和com.mongodb.client之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆