nswbmw / koa-mongo

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

Accessing the MongoClient outside of ctx #46

Closed fgeorges closed 3 years ago

fgeorges commented 3 years ago

Hi,

[ This is not an issue per se, more of a question. I did not find any other place to ask it, sorry if there is a better place for that (I'd gladly repost it elsewhere if needed, of course.) ]

I am using koa-mongo and koa-passport. Passport requires to provide the function deserializeUser(), which needs access to the database. But it is defined outside of a middleware, and has no access to ctx. And the MongoClient is made available on ctx.

Is there another way to access the mongo client? Maybe at the Koa app level?

Thank you!

nswbmw commented 3 years ago

You may need a singleton db instance, check Mongolass.