mongodb/node-mongodb-native — pull request #638 by ivanstoyanov (2012-06-18 02:48:36+00:00)
Title: Replica set with authentication issue

Setup - the initial authentication is done against the admin database and then other databases are requested via db.db. The credential information is lost (auths in db) and when the primary instance fails, the retry against the new primary fails, because the driver is re-authenticating against the wrong database (whoever is being requested at that time).

This change:
1) preserves auths in Db.prototype.db
2) adds a parameter corresponding to the a database name down to 'Create authentication command'
3) adds an optional parameter to Db.prototype.authenticate, which is again the database name.
4) during retry, the correct db name is passed.

I don't see any better alternatives. The stuff in admin.js doesn't help.

P.S. This issue happened to me in production during the recent AWS outage, and the failover failed due to auth.