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

Auto reconnect #306

Closed
donpark opened this issue Apr 4, 2011 · 10 comments
Closed

Auto reconnect #306

donpark opened this issue Apr 4, 2011 · 10 comments

Comments

@donpark
Copy link

donpark commented Apr 4, 2011

Mongoose-based apps currently has to be restarted when connection fails, times out, or when mongod restarts. There has to be a better way.

@ghost
Copy link

ghost commented May 19, 2011

Agree. I am using node_redis module and it has "connected" field and "on error" callback. If disconnect happened - "connected" field set to false and node_redis try to connect repeatedly firing "on error" until the connection established.

Maybe Mongoose should work on the same model.

@taf2
Copy link

taf2 commented Jul 1, 2011

this might be helpful: https://gist.github.com/1058819

@robertothais
Copy link

The native mongodb driver has an auto reconnect feature, but Mongoose doesn't provide the option to pass the flag that turns it on when the connection is established. This is a workaround to enable it:

var mongoose = require('mongoose');
mongoose.connect('mongodb://...');
mongoose.connection.db.serverConfig.connection.autoReconnect = true

@taf2
Copy link

taf2 commented Jul 4, 2011

@rpbertp13, that's much nicer than my solution thanks!

@donpark
Copy link
Author

donpark commented Jul 5, 2011

@rpbertp13 last time I tried that (several months ago), that didn't do anything. perhaps it's working now.

@robertothais
Copy link

Works for me with the current version (0.9.6.1). The code is definitely there: https://github.com/LearnBoost/mongoose/blob/master/support/node-mongodb-native/lib/mongodb/connection.js#L233-233

@donpark
Copy link
Author

donpark commented Jul 5, 2011

cool. I'll give it a try again but I hink this issue should be left open until the issue is directly addressed by mongoose, at the API level even.

@mattcobb
Copy link

mattcobb commented Jul 6, 2011

Using 1.5.
dbConnection = mongoose.createConnection(....);
mongoose.connection.db.serverConfig.connection.autoReconnect = true;

throws:
TypeError: Cannot read property 'serverConfig' of undefined"

@justmoon
Copy link
Contributor

justmoon commented Aug 8, 2011

This syntax worked for me:

dbConnection = mongoose.createConnection(....);
dbConnection.db.serverConfig.options.auto_reconnect = true;

See also: #410

@aheckmann
Copy link
Collaborator

Just merged pull #410 into branch v1.x in this morning. Options can now be passed to Server, ReplSetServer, and Db. The auto_reconnect option is enabled by default.

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

6 participants