index.js:
..
var MongoStore = require( 'connect-mongo' )( session );
var db = require( path.join( __dirname, 'db.js' ) );
..
db.connect( conStr, function( err ) {
if( err ) {
console.log( 'Connect to mongoDb failed!' );
process.exit( 1 );
} else {
app.listen( port, function() {
console.log( 'App listening on port: ' + port );
});
}
});
...
app.use( session ({
name: 'bbn.sid',
secret:'shopusersessionsecret',
resave: false,
saveUninitialized: false,
store: new MongoStore( { db: db.get() } ),
cookie: {
maxAge: 180 * 60 * 1000,
}
}));
..
db.js:
...
var database = null;
function connect( url, done ) {
if( database ) return done();
MongoClient.connect( url, function( err, db ) {
if( err ) return done( err );
database = db;
done();
});
}
function get() {
return database;
}
...
If i'm creating the new connection to the session store (by providing url) it seems OK, but if i'm trying to use an existing mongo connection i get the following error:
E:\Proj\bbn\node_modules\connect-mongo\src\index.js:105
throw new Error('Connection strategy not found');
^
Error: Connection strategy not found
at MongoStore (E:\Proj\bbn\node_modules\connect-mongo\src\index.js:105:23)
at Object.<anonymous> (E:\Proj\bbn\index.js:50:12)
at Module._compile (module.js:541:32)
It seems, that the session middleware is calling rather then mongo db connection initializes?