Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read preference does not seem to be working #1833

Closed
ryanogle opened this issue Dec 16, 2013 · 3 comments
Closed

Read preference does not seem to be working #1833

ryanogle opened this issue Dec 16, 2013 · 3 comments

Comments

@ryanogle
Copy link

I was on an older version of mongoose and mongo driver (mongoose@3.6.4 & mongodb@1.2.14), and since upgrading to the newest version (mongoose@3.8.1 & mongodb@1.3.23) my read preference set on the collection level no longer seems to work. I also tried to set it on the query level, and it doesn't seem to work:

    User.find({
      my_field: {
        $in: my_ids
      }
    }, my_fields, function (err, results) {
      cb(err, results);
    }).read('secondary');

Everything seems to be going to the primary. Rolling back to the old versions shows the expected behavior - queries going to the secondary.

I also tried to follow exactly the mongoose api docs:

    var query = User.find({
      my_field: {
        $in: my_ids
      }
    }, my_fields ).read('secondary');

    query.exec(function (err, result) {
      cb(err, result);
    });

And same result, queries going to primary only. When I roll back to 3.6.4, reads start going to the secondaries (I'm setting the read preference on the collection).

@dpomerantz
Copy link

I have noticed the same thing. I believe it has to do with some of the createConnection() code that stores a flag as read_preference when it should be readPreference.

When I add the options to db under server options it works better.

e.g.

var options = {
// some other stuff
db : {
readPreference : "secondary"
}
};

To confirm the bug, I added a print statement in the code that searches for a machine to connect to. When only including in the url, the code uses a function called checkoutWriter() (part of mongo driver). When I add the setting above, it properly hits the checkoutReader() code.

@aheckmann
Copy link
Collaborator

Please retest using 3.8.7 and let us know.

@vkarpov15
Copy link
Collaborator

Stale issue, re-open if this is still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants