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.
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How to represent an array with mixed types
MongoDB Java drivers in the 3.0 - 3.12.2 version range have an 'Uber' driver which contains both legacy client implementations as well as the newer client. When considering org.bson.Document compared to com.mongodb.BasicDBObject the class
org.bson.Document
is used with the newer client stack, whereascom.mongodb.DBobject
orcom.mongodb.BasicDBObject
are used in the legacy client stack. It can be really confusing having both legacy and newer stuff in the same driver. If you are only interested in the newer client see the driver called 'mongodb-driver-sync' MVN repo at https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync. If you only want legacy, see https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-legacy. Some artifacts are universal, likecom.mongodb.WriteConcern
. As such they will exist in both legacy and sync. My understanding is that this 'Uber' driver will not exist in the version 4.0 or later. The legacy driver is lacking session support, transaction support, and change streams. Choose wisely.Basic DBobject is not deprecated . The only deprecated part in the BasicDBobject is
DBPointer
class and few other methods liketoString() and getId()
Document implements
Map<String, Object>
and there is less code to write compared to Basic DB objectDBObject 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:
it is an interface rather than a class, so it’s API can not be extended without breaking binary compatibility.
It doesn’t actually implement Map.
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.