0

We have an app built using node.js, mongo with mongoose. We have a replicated test database set up. We are using connect-mongostore for session management in express. I'm trying to get my database to timeout when it goes away. So, if connect with my app, (uses rest services,) then kill mongo on both the primary and secondary server, then I would like to timeout the request between node and mongo to return the error. However, it never seems to do that.

Any ideas?

Here is what I have so far:

For connect mongostore, for session:

"servers":[{"host":"rs0_primary.myapi.com","port":27017,"options":{"autoReconnect":true,"socketOptions":{"connectTimeoutMS":10000,"socketTimeoutMS":10000,"keepAlive":1,"encoding":"utf8"}}},{"host":"rs0_secondary.myapi.com","port":27017,"options":{"autoReconnect":true,"socketOptions":{"connectTimeoutMS":10000,"socketTimeoutMS":10000,"keepAlive":1,"encoding":"utf8"}}}]

For mongoose:

mongodb://user1:password1@rs0_primary.myapi.com/stuff,user1:password1@rs0_secondary.myapi.com/esp?replicaSet=rs0&connectTimeoutMS=10000&socketTimeoutMS=10000
gustavohenke
  • 40,997
  • 14
  • 121
  • 129
CargoMeister
  • 4,199
  • 6
  • 27
  • 44
  • It may not directly answer your question, but this post has a lot of useful information in this area: http://stackoverflow.com/questions/13980236/does-mongodb-have-reconnect-issues-or-am-i-doing-it-wrong – JohnnyHK Dec 04 '13 at 13:30
  • Thanks. Good info, but still not what I need. I have the opposite problem - can't make it go away. We'd like it to fail so we can catch the error and pass an error back gracefully to the mobile client, instead of it just sitting there spinning. – CargoMeister Dec 04 '13 at 21:05
  • Take a look at http://stackoverflow.com/questions/9386066/nodejs-mongoose-timeout-on-connection – James Wahlin Jan 08 '14 at 17:12
  • 1
    Have you tried connect-mongo instead of connect-mongo-store? I have a simple app which does what I think you want, throws a socket exception when the DB is killed. Module versions are: connect-mongo@0.4.0, mongoose@3.8.3, express@3.4.7. Standard config calls. – Ger Hartnett Jan 10 '14 at 11:41
  • The problem with connect-mongo is that it does not support replica sets. Our database is using replica sets. – CargoMeister Jan 13 '14 at 16:34

0 Answers0