A
A
Alexander Wolf2013-05-03 23:16:27
MongoDB
Alexander Wolf, 2013-05-03 23:16:27

Connect-mongo creates a new session on every page refresh?

Hello! Connect-mongo creates a new session every time the page is refreshed. In 10 minutes they can get ~ 50 pieces (and that's just me). Please help how to solve this problem?
The code

var express = require('express');
var MongoStore = require('connect-mongo')(express);
var pages = require('./routes/pages');

var db = require('mongoose').connect('mongodb://user:[email protected]:port/db');
var app = express();
var server = require('http').createServer(app).listen(process.env.PORT);

app.set('db', db);
app.set('views', 'views');
app.set('view engine', 'jade');
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.session({
  store: new MongoStore({
    url: 'mongodb://user:[email protected]:port/db',
    stringify: false
  }),
  cookie: {
    maxAge: 24 * 360000
  },
  key: 'xxxxxx',
  secret: 'ararar'
}));
app.use(app.router);
app.use(express.static('public'));

app.get('/', function (req, res) { res.end('hello world') });

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
pomeo, 2013-05-04
@mannaro

As far as I remember it depends on app.use location sequences. Plus your code is non-standard for express.

C
ch3sh1r3, 2013-05-04
@ch3sh1r3

clear_interval, no?

Y
Yuri Shikanov, 2013-05-04
@dizballanze

Why not express-session-mongo?

L
likejavascript, 2013-05-04
@likejavascript

I don’t know if it will help you, but personally, when describing app.use(express.session) I use a mongoose connection:
var db = require('mongoose').connect('mongodb://user:[email protected]:port/db');
app.use(express.session({ store: new MongoStore({ mongoose_connection: db.connections[0] }) }));
I don’t create a new session every time I refresh the page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question