Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error setting TTL index on collection : sessions #85

Closed
DaftMonk opened this issue Feb 13, 2014 · 11 comments
Closed

Error setting TTL index on collection : sessions #85

DaftMonk opened this issue Feb 13, 2014 · 11 comments

Comments

@DaftMonk
Copy link
Member

Please post if you experience this error. Also, try adding this callback to your express session and see if that solves the issue.

app.use(express.session({
  secret: 'angular-fullstack secret',
  store: new mongoStore({
    url: config.mongo.uri,
    collection: 'sessions'
  }, function () {
    console.log("db connection open");
  }))
}));

This possible solution was mentioned here: jdesboeufs/connect-mongo#58 (comment)

@chrisdhanaraj
Copy link

Hmmm, this error still appears for me? Just scaffolded out the app, set the DB to my MongoHQ one

Edit: Oh super weird, for me the fix was actually removing the commit. I might just have a wonky setup somewhere in this or something.

@DaftMonk
Copy link
Member Author

@chrisdhanaraj Could you try adding

auto_reconnect: true

to the mongoStore configuration? There are reports of that fixing this issue as well.

@chrisdhanaraj
Copy link

Yeah, that's actually the first thing I tried - still the same error. Removing the callback was what fixed it for me

@mkelley33
Copy link

This error is still appearing for me. I tried with the callback and without it. I've also tried adding auto_reconnect: true. @chrisdhanaraj any other suggestions that I might try? Thank you.

@davisford
Copy link

I'm seeing it pop up also, in dev mode, while running grunt serve. Also seeing it running the dist build. I've got the mongoStore callback identified above in the code as well. I'll try @innon's suggestion to move the express.listen call into the callback.

@innon
Copy link

innon commented May 7, 2014

First off, great work on the generator :)

I'm getting this when I run tests. All the tests pass, but I get this error at the start of the test run. I'm running this on a Macbook with a SSD disk, so maybe the tests run faster than the database connection (just guessing). Tried adding the auto_reconnect parameter to no avail.

@innon
Copy link

innon commented May 7, 2014

I did some tests, I seem to have solved the issue by starting the server once the session store was ready. I modified the last lines of server.js to look like this

// Start sesion store, and start the server once the sessio store is ready
// Persist sessions with mongoStore
app.use(express.session({
   secret: 'angular-fullstack secret',
   store: new mongoStore({
      url: config.mongo.uri,
      collection: 'sessions',
      auto_reconnect: true
   }, function () {
       console.log("db connection open, starting server");

       app.listen(config.port, function () {
         console.log('Express server listening on port %d in %s mode', config.port, app.get('env'));
      });
   })
}));


// Start Expose app
exports = module.exports = app;

And I also commented the session store code out of express.js. I don't know whether this is the optimal solution but it did the trick for me, I managed to run tests on mongodb without getting the TTL error.

@davisford Update: While this will fix the testing issues, I noticed that this will cause authentication issues in the client (random 401 replies from the server) causing the application not to work properly. Sorry about that.

@outrightmental
Copy link

Also, turns out my real issue was specific to testing. Talk about deja vu, I found my own thread http://stackoverflow.com/questions/22582648/node-js-mocha-unit-testing-error-re-mongoose-mocks-with-mockgoose-error-setti

@ralyodio
Copy link

This is still happening for me. I could not figure out how to fix.

@outrightmental
Copy link

@chovy would it be possible to put together a gist focusing on the exact issue you're experiencing. I'd be happy to take a look at some more specific information.

@ralyodio
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants