ReadPreference usage

67 views
Skip to first unread message

Senor Cardgage

unread,
Aug 31, 2012, 3:08:59 PM8/31/12
to mongodb...@googlegroups.com
I'm confused about how to use ReadPreference.  The following is listed as a breaking change for v1.6:
  • Commands are no longer always sent to primaries. If you are expecting this behavior, ensure that your read preference is set to Primary.
I need to always read from the primary (ReadPreference.Primary), but how is that done?

Robert Stam

unread,
Aug 31, 2012, 3:29:59 PM8/31/12
to mongodb...@googlegroups.com
Sorry about the confusing wording...

What we meant is: commands are now routed to replica set members the same as any other queries, based on the ReadPreference.

The default ReadPreference is Primary, so by default all commands go to the primary, as do all queries. But if your ReadPreference is anything else, then it is possible that commands will go to a secondary.

To set the ReadPreference for a command you would do it using a MongoDatabaseSettings object that you would then pass to GetDatabase. You would only need to do this if you wanted to use a ReadPreference other than the default.
Reply all
Reply to author
Forward
0 new messages