0.0.6 • Published 7 years ago
mongoose-express-session-beta v0.0.6
Mongoose Store
A simple http://www.senchalabs.org/connect/session.html#exports.Store implementation using http://mongoosejs.com/ to persist to a https://www.mongodb.org/ data store.
Usage
var mongoose = require('mongoose');
var Store = require('express-session').Store;
var MongooseStore = require('mongoose-express-session')(Store);
var thirtyDaysToSecs = 2592000
app.use(require('express-session')({
secret: 'keyboard cat',
resave: false,
rolling: false,
saveUninitialized: true,
store: new MongooseStore({
/* configuration */
connection: 'mongodb://localhost/connect-sessions',
mongoose: mongoose,
sessionLifespan: thirtyDaysToSecs,
modelName: 'Session'
})
}));The configuration properties require one of:
connectionas an already connected mongoose instance:
var mongoose = require('mongoose');
mongoose.connect('http://server/db');
new MongooseStore({connection: mongoose});mongooseinstance and aconnectionstring
var mongoose = require('mongoose');
new MongooseStore({connection: 'http://server/sessions', mongoose: mongoose});mongooseas an already connected mongoose instance without theconnectionstring
var mongoose = require('mongoose');
mongoose.connect('http://server/db');
new MongooseStore({mongoose: mongoose});When just supplying mongoose, the default connection string mongodb://localhost/connect-sessions will be used,
allowing for connecting the session model without impacting the application database.
storeinstead of passing the Store constructor up-front, it can also be passed into the configuration
var MongooseStore = require('mongoose-express-session')();
var mongooseStore = new MongooseStore({
mongoose: mongoose,
store: require('express-session').Store
});These are optional properties of configuration
sessionLifespanas an expiry of session on the store
If it doesn't given as a configuration, the default number 60 * 20 will be used.
modelNameas an name of model where Session will be stored.
If it doesn't given as a configuration, the default string Session will be used.
Project Status
Currently a work in progress and not production-ready.