MongoDB BasicDBObject vs Document in java

╄→гoц情女王★ 提交于 2019-12-21 12:22:29

问题


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.


回答1:


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

Document implements Map<String, Object> and there is less code to write compared to Basic DB 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. it is an interface rather than a class, so it’s API can not be extended without breaking binary compatibility.

  2. It doesn’t actually implement Map.

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

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.



来源:https://stackoverflow.com/questions/44878605/mongodb-basicdbobject-vs-document-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!