Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:12+00:00 2026-05-30T17:25:12+00:00

I am currently having a hell of time trying to store sessions in MongoDb.

  • 0

I am currently having a hell of time trying to store sessions in MongoDb.

I’ve tried express-session-mongo and connect-mongodb and both give me the same “500 internal server error” when I try to load the login page. Which leads me to think maybe there is a conflict with mongoose-auth somewhere.

Anyway here is my setup:

app.js:

var MongoStore = require('connect-mongodb');
var MongoDb = require('mongodb').Db;
var Server = require('mongodb').Server;

var db = new MongoDb('myDb', new Server('localhost', 27017, {auto_reconnect: true, native_parser: false}));

app.configure(function() {
  app.use(express.logger({format: 'dev'}));
  app.set('views', __dirname + '/../views');
  app.set('view engine', 'jade');
  app.set('view options', { layout: false });
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(mongooseAuth.middleware());
  app.use(require('./mysite').middleware());
  app.use(express.methodOverride());
});


app.configure('production', function(){
  var oneWeek = 657450000;
  app.use(express.static(__dirname + '/../public', { maxAge: oneWeek }));
  app.use(express.session({ store: new MongoStore({db: db}), secret: 'super secret' }));
  app.use(express.errorHandler());
});

// Routes
require('./routing.js');

mongooseAuth.helpExpress(app);

app.listen(3000);
console.log('Express server listening on port %d in %s mode', app.address().port, app.settings.env);

userModel.js

var Schema = mongoose.Schema;
var mongooseTypes = require("mongoose-types");
var mongooseAuth = require('mongoose-auth');
mongooseTypes.loadTypes(mongoose);

var everyauth = require('everyauth')
everyauth.debug = true;

var UserSchema = new Schema({any: {}});

UserSchema.plugin(mongooseAuth, {
    everymodule: {
      everyauth: {
          User: function () {
            return User;
          }
      }
    }
    , password: {
      loginWith: 'email'
      , extraParams: {
            phone: String
          , username: String
        }
      , everyauth: {
            getLoginPath: '/login'
          , postLoginPath: '/login'
          , loginView: 'account/login.jade'
          , getRegisterPath: '/register'
          , postRegisterPath: '/register'
          , registerView: 'account/register.jade'
          , loginSuccessRedirect: '/login/success'
          , registerSuccessRedirect: '/register/success'
        }
    }
});

mongoose.model('User', UserSchema);
User = mongoose.model('User');

At this moment in time I’m really just trying to use MongoDb as the session store, but again I get a 500 error w/ no information whatsoever in the node.js console when I try to load the login page.

Any help would be greatly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:25:13+00:00Added an answer on May 30, 2026 at 5:25 pm

    It ended being a problem of the various modules: connect-session-mongo / express-session-mongo / connect-mongo, using connect 2.0.1 and Express using connect 1.8.5.

    Apparently the dependency clash here prevented the session store modules to access the ‘req.secret’ property.

    To make it work I ended using the module connect-mongodb that is still using connect 1.8.5, just like Express.

    The reason I couldn’t make connect-mongodb work before though was user error, I tried too hard to use copy/paste from online examples instead of my head.

    Here is the configuration code that ended up working for me with connect-mongodb:

    var Session = require('connect-mongodb');
    
    app.configure('production', function(){
      var oneWeek = 657450000;
      app.use(express.static(__dirname + '/../public', { maxAge: oneWeek }));
    
      var session = express.session({
            store: new Session({
                  url: 'mongodb://localhost:27017/test', 
                  maxAge: 300000
            }),
            secret: 'superTopSecret' 
      });
      app.use(session);
    
      app.use(mongooseAuth.middleware());
      app.use(require('./mySite').middleware());
      app.use(express.methodOverride());
      app.use(express.errorHandler());  
    });
    

    Hope this helps anyone else who runs into this issue. If you have any suggestion/improvement on this solution, I’d be glad to hear it. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well I'm having a hell of a time trying to get my CPU down
I am currently having unnecessary trouble trying to test out RubyMine. My biggest problem
I'm having a hell of a time getting WCF Data Services to work within
i'm currently having some issues by using the cakePHP data validation. I've tried to
I'm having a hell of a time using CGImageCreateWithImageInRect to crop a photo. My
I am currently having issues redirecting both STDError and STDOutput. What I want to
I am currently having a problem with getting the correct time for an event
I´m currently having a hard time with the autoformatter in eclipse... aiming on my
Having a hell of a time using http://plugins.jquery.com/project/bgImageTransition to create a slideshow of crossfaded
I currently have separate game_date and game_time fields and I am having a hell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.