简体   繁体   English

Java MongoDB:com.mongodb.DB和com.mongodb.client有什么区别

[英]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.DBDBCollection库包括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.MongoClientcom.mongodb.client.MongoDatabase See the official tutorial of the Java driver here . 此处查看Java驱动程序官方教程

暂无
暂无

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

相关问题 包com.mongodb.client不存在 - package com.mongodb.client does not exist java 控制台程序不存在包 com.mongodb.client - package com.mongodb.client does not exist for a java console program “错误:(3,19) java: 包 com.mongodb.client 不可见” - 将 MongoDB 与 IntelliJ 中的 Maven JavaFX 项目连接时出错 - "Error:(3,19) java: package com.mongodb.client is not visible" - Error connecting MongoDB with a Maven JavaFX project in IntelliJ MongoDB Java API:com.mongodb.DBCollection.Save()和com.mongodb.DBCollection.Insert()之间的区别? - MongoDB Java API: Difference between com.mongodb.DBCollection.Save() and com.mongodb.DBCollection.Insert()? 在SpringBoot提供的com.mongodb.client package中找不到MongoClient class - Cannot find the MongoClient class in the com.mongodb.client package provided by SpringBoot com.mongodb.client.MongoClient 和 com.mongodb.MongoClient 的区别 - Differences between com.mongodb.client.MongoClient and com.mongodb.MongoClient 什么是“com.mongodb.MongoSocketReadException”和“com.mongodb.MongoTimeoutException”的解决方案 - What is the solution "com.mongodb.MongoSocketReadException" and "com.mongodb.MongoTimeoutException" MongoDB init 在引导程序中抛出 java.lang.NoClassDefFoundError: com/mongodb/client/internal/SimpleMongoClient - MongoDB init throw in bootstrap java.lang.NoClassDefFoundError: com/mongodb/client/internal/SimpleMongoClient mongodb Java Driver build error: cannot access com.mongodb.client.result.InsertOneResult, class file not found - mongodb Java Driver build error : cannot access com.mongodb.client.result.InsertOneResult, class file not found Java:无法访问com.mongodb.ServerAddress-Java未连接到MongoDB - java: cannot access com.mongodb.ServerAddress - java not connecting to MongoDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM