MongoCollection vs DBCollection and Read Preference and Thread Safety

1,214 views
Skip to first unread message

api...@gmail.com

unread,
Jun 10, 2015, 5:17:53 PM6/10/15
to mongod...@googlegroups.com
I found out that MongoCollection is preferred over DBCollection but I haven't  found any reasons so I tried to find them on my own.

Per docs at this link http://mongodb.github.io/mongo-java-driver/3.0/driver/reference/crud/ it seems that MongoCollection is immutable so setting read preference
on current collection return the new collection without affecting existing one.
I also looked at setReadPreference usage in DBCollection and it seems that it lacks thread safety in order to change read preference on each data access call on the same instance of collection.
Is this accurate statement and are there any other reasons to prefer MongoCollection over DBCollection?

Thank you,
Andre Piwoni

Ross Lawley

unread,
Jun 11, 2015, 6:52:04 AM6/11/15
to mongod...@googlegroups.com
Hi Andre,

The main reason is because the DB class and all code underneath it has been deprecated and will eventually be removed, including the DBCollection class.  The replacement is the new MongoDatabase class which provides the new generic MongoCollection class, allowing users to efficiently use domain objects with MongoDB.  The whole MongoCollection API conforms to the new cross driver CRUD API specification. It has also been designed to be extendable in the future without having to override methods as new features are added to MongoDB.

For an in depth introduction to the 3.0 driver and some of the benefits / design decisions made when developing it, please see the introduction post: https://www.mongodb.com/blog/post/introducing-30-java-driver

Ross


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/a0eff9d4-6258-4cd5-a353-35aebb0c59dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

name     : "Ross  Lawley",

  title    : "JVM Software Engineer",

  location : "London, UK",

  twitter  : ["@RossC0", "@MongoDB""@MongoDBInc"],

  facebook : ["MongoDB", "MongoDB, Inc."] }

Reply all
Reply to author
Forward
0 new messages