I’ve found three library of session storing in MongoDB: connect-mongodb, connect-mongo, connect-session-mongo
Which is the best?
EDIT: So if I’ll use connect-mongodb I have to make two db connections. First for the session store:
var connect = require('connect')
, Db = require('mongodb').Db
, Server = require('mongodb').Server
, server_config = new Server('localhost', 27017, {auto_reconnect: true,
native_parser: true})
, db = new Db('test', server_config, {})
, mongoStore = require('connect-mongodb');
connect.createServer(
connect.bodyParser(),
connect.cookieParser(),
connect.session({
cookie: {maxAge: 60000 * 20} // 20 minutes
, secret: 'foo'
, store: new mongoStore({db: db})
})
);
Second for my mongoose connection:
var mongoose = require('mongoose');
db = mongoose.connect('mongodb://localhost/test');
....
this is so?
https://github.com/masylum/connect-mongodb is listed on the 3rd party middleware (session stores) page of Connect, it has the most followers (111) and it’s actively updated (last update ~ 8 hours ago), so I would probably pick that one if I were you.
Edit:
About your second question, how to use connect-mongodb along with Mongoose, here’s an example:
Nodepad is a real app that uses Express, connect-mongodb and Mongoose, you can checkout the main app file here: https://github.com/alexyoung/nodepad/blob/master/app.js