ExpressJS Mongoose Session Store

So as it happens, I use Express when I need to build a quick webapp in NodeJS, and I sometimes use MongoDB. I always use MongooseJS because I just find it easier to work with than the standard JS driver.

So that works well for the most part. The one issue I end up having though is I inevitably need a DB backed session store to sync sessions among servers and MongoDB since I am already using it seems like a natural choice. The problem is that using connect-mongo ends up making me have to use a seperate connection from my Mongoose connection. So while I can pass it a Mongoose connection, it actually will just read out the connection data.

The reason this is less than ideal is, now I would have to end up having to deal with disconnect/reconnect to the database seperately from my main Mongoose connection pool when I really just want to piggy back on connections I already have.

So I decided to make express-mongoose-store which does just that. It does the same as connect-redis or connect-mongo does, except you also pass it your Mongoose connection and you just get to use it without maintaining another config or maintaining connection state for your sessions backend.

Hopefully someone else finds this useful.