Dec 13th, 2012, 04:07 PM
Configuring read preferences for MongoDB in Spring Data on collection level
I am using Spring Data MongoDB latest version 1.1.1RELEASE and wondering if it possible to add read preference on collection level. Something that possible with plain MongoDB driver. I want all my reads for particular collection go to the slaves to distrubute read operations. Is that possible?
From mongo driver documentation:
Continuing with our sample application, we decide that we want to send our read requests to the nearest node to reduce request latency. The Java driverís read preference API gives a couple of ways of doing this, the easiest is to simply use the nearest mode.
DBObject query = new BasicDBObject("name", "simple doc")
DBObject result =
coll.findOne(query, null, ReadPreference.nearest());
Tags for this Thread