connect-mongostore icon indicating copy to clipboard operation
connect-mongostore copied to clipboard

URL parser doesn't work with replica sets

Open rtgibbons opened this issue 9 years ago • 5 comments

Right it's using the node.js url module to parse it, with works for single hosts but doesn't work with replica sets.

Some Examples:

  • mongodb, the official driver, https://github.com/mongodb/node-mongodb-native/blob/master/lib/mongodb/connection/url_parser.js
  • mongoose uses muri - https://www.npmjs.org/package/muri
  • https://www.npmjs.org/package/mongodb-uri
  • https://www.npmjs.org/package/mongo-uri

I'd suggest either using mongodb's url_parser or muri

What do you think?

rtgibbons avatar Jul 20 '14 19:07 rtgibbons

I think you're right :) I'd go with mongo's own parser. I'm also planning to switching this module to use MongoClient so it supports connection string but I don't have the bandwidth at the moment. I'll try to update URL parser ASAP (or I can merge your PR if you make one!).

diversario avatar Jul 21 '14 04:07 diversario

Nice, I currently don't have the bandwidth either. I'll add this to the list of things to hack on though as there is a chance I'll be able to use this module more often.

rtgibbons avatar Jul 21 '14 13:07 rtgibbons

I've put something in that handles this. It does use mongodb's parse function and then maps the objects to this modules internal structure.

https://github.com/diversario/connect-mongostore/pull/25

It doesn't use MongoClient.connect yet, as that broke just about every test. I did have a hacked up version that used it in my first commit, and it does work. But it broke all of the other paths with config classes etc. This pull request at least seems to work with all of the existing approaches.

seanmwalker avatar Oct 20 '14 16:10 seanmwalker

As I mentioned in the #25 there's a branch feature/use-mongoclient that breaks compatibility with current versions and uses MongoClient. I would really love for someone to try it in real life!

diversario avatar Oct 21 '14 02:10 diversario

Just a note, I tried the branch on our codebase where we use a replica set connection string. It worked fine for this app. I killed the primary and once the election completed it was responsive as expected. So that path works pretty well.

seanmwalker avatar Oct 21 '14 16:10 seanmwalker