MongoDB BasicDBObject与Java中的文档 [英] MongoDB BasicDBObject vs Document in java

查看:1177
本文介绍了MongoDB BasicDBObject与Java中的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将MongoDB v3.2.0与Mongo Java Driver 3.0.4版本一起使用.我正在Java中使用BasicDBObject(已弃用)而不是使用Document,因为我需要在独立的Java项目中进行许多更改以转换为Document.谁能告诉我换成Document,内存和大集合插入和读取是否会有任何性能改进.有什么方法可以改善使用Java在MongoDB上的频繁写入和读取操作.

I am using MongoDB v3.2.0 with Mongo Java Driver 3.0.4 version. I am using the BasicDBObject (deprecated) instead of using the Document in java, as I need to do many changes for converting to Document in my standalone java project. Can anyone tell me changing into Document, will there be any performance improvement in memory and large collection inserts and reads. Is there any way to improve my frequent write and read operations on MongoDB using java.

推荐答案

不推荐使用基本的DBobject. BasicDBobject中仅弃用的部分是DBPointer类和其他一些方法,例如toString() and getId()

Basic DBobject is not deprecated . The only deprecated part in the BasicDBobject is DBPointer class and few other methods like toString() and getId()

文档实现了Map<String, Object>,与基本DB对象相比,要编写的代码更少

Document implements Map<String, Object> and there is less code to write compared to Basic DB object

DBObject 尽管不建议将其用于新应用程序,但是从2.x驱动程序系列升级的那些程序可能会继续使用DBObject接口来表示BSON文档. DBObject与Document相似之处在于,它将BSON值表示为Object,但是它具有一些无法克服的缺点:

DBObject Although not recommended for new applications, those upgrading from the 2.x driver series may continue to use the DBObject interface to represent BSON documents. DBObject is similar to Document in that it represents BSON values as Object, but it has a few shortcomings that were impossible to overcome:

  1. 它是一个接口而不是一个类,因此如果不破坏二进制兼容性,则无法扩展它的API.

  1. it is an interface rather than a class, so it’s API can not be extended without breaking binary compatibility.

它实际上并未实现Map.

It doesn’t actually implement Map.

因为它是一个接口,所以需要一个单独的名为BasicDBObject的具体类来实现该接口

Because it is an interface, a separate concrete class called BasicDBObject which implements that interface, is required

Bson 为了将所有这些结合在一起,驱动程序包含一个小而强大的接口,称为Bson.代表BSON文档的任何类,无论是包含在驱动程序本身中还是来自第三方的,都可以实现此接口,然后可以在需要BSON文档的高级API中的任何位置使用.

Bson To tie these all together, the driver contains a small but powerful interface called Bson. Any class that represents a BSON document, whether included in the driver itself or from a third party, can implement this interface and can then be used any place in the high-level API where a BSON document is required.

这篇关于MongoDB BasicDBObject与Java中的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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