nswbmw / koa-mongo

MongoDB middleware for koa, support connection pool.
145 stars 31 forks source link

Add authSource to url and options #37

Closed South-Paw closed 5 years ago

South-Paw commented 5 years ago

Hey, another contribution in parallel to #36.

I split these apart because I'm unsure if you will want both, or one, or the other - so tried to make this easier.

If you enable auth on your mongo server (and you should have if you're going anywhere near production of course...) then you'll put your user in the admin database.

When we connect and pass the db: 'test' option, mongo attempts to use that test db as the auth database however this isn't correct cause we of course put our user in the admin database, not test.

The solution is to simply provide authSource in the connection url - if this doesn't apply then authSource could simply be set to (or maybe even default to) the same as the db option.

Thanks again, hope this is useful - feel free to discuss of course 😄

nswbmw commented 5 years ago

@South-Paw Thanks!

nswbmw commented 5 years ago

Bump v1.7.0