MongoDB BasicDBObject vs Document in java

Viewed 10594

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.

2 Answers

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, whereas com.mongodb.DBobject or com.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, like com.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.

Related