Error: Error setting TTL index on collection : sessions; when using fully instantiated node-mongo-native object #70

skotchio opened this Issue Jun 10, 2013 · 4 comments


None yet
6 participants

In the following code I use existing db object:

var mongoClient = new MongoClient(new Server('localhost', 27017, {auto_reconnect:   true})); (err, mongoClient) {
var db = mongoClient.db('db_name');
db.authenticate('user', 'password', function () {err, result} {
   if (err || !result) return console.log('error');

      store: new MongoStore({
        db: db

I think the problem in because here not nessesary check openCalled because I use existing object. So if I replace that line to just


All works fine

Same problem here. Any news regarding a fix?

korczis commented Sep 7, 2013

Same here.


If the first request to express comes after some time (say 500ms) then the problem isn't there. However, if the first request comes right after express has been started, then connect-mongo hits this problem.

The fix suggested doesn't work for me, other ideas?

This happens when the connection to the database is not established and a client query for the session. A way to fix this would be to wait for the connection to be establish before doing any work.

To do this, wait for the callback when constructing the mongoStore
store: new MongoStore({url: databaseUrl, callback)

@jdesboeufs jdesboeufs added a commit that referenced this issue Dec 24, 2014

@jdesboeufs jdesboeufs Rewrite MongoStore initialization
* Re-use existing or upcoming mongoose connection
* Re-use existing or upcoming node-mongodb-native connection
* Accept full-featured MongoDB connection strings + advanced options
* Compatible with legacy config
* Replace callback by `connected` event
* Add debug

Fix #51, #58, #62, #66, #70, #85, #94, #96, #115, #117, #120
Fix #124, #128, #129, #130, #131, #133, #134

jdesboeufs closed this Dec 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment