node.jsexpressmongoosenode.js-connectconnect-mongo

Node: "Error setting TTL index on collection" when using connect-mongo for sessions


I am trying to deploy an Express app to heroku and get the following error:

2013-01-28T12:44:55+00:00 heroku[web.1]: Starting process with command `coffee    server.coffee`
2013-01-28T12:44:57+00:00 app[web.1]: Express server listening on port 13715
2013-01-28T12:44:57+00:00 app[web.1]: /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:537
2013-01-28T12:44:57+00:00 app[web.1]:               ^
2013-01-28T12:44:57+00:00 app[web.1]:         throw err;
2013-01-28T12:44:57+00:00 app[web.1]:     at Db.indexInformation (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1372:30)
2013-01-28T12:44:57+00:00 app[web.1]: Error: Error setting TTL index on collection : sessions
2013-01-28T12:44:57+00:00 app[web.1]:     at module.exports._get_collection (/app/node_modules/connect-mongo/lib/connect-mongo.js:137:23)
2013-01-28T12:44:57+00:00 app[web.1]:     at Cursor.toArray (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:152:22)
2013-01-28T12:44:57+00:00 app[web.1]:     at Db.ensureIndex (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1228:28)
2013-01-28T12:44:57+00:00 app[web.1]:     at Cursor.nextObject.self.queryRun (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:594:39)
2013-01-28T12:44:57+00:00 app[web.1]:     at Db._executeQueryCommand (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1814:5)
2013-01-28T12:44:57+00:00 app[web.1]:     at Cursor.close (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:947:5)
2013-01-28T12:44:57+00:00 app[web.1]:     at Cursor.nextObject.commandHandler (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:594:21)
2013-01-28T12:44:57+00:00 app[web.1]:     at EventEmitter.emit (events.js:126:20)
2013-01-28T12:44:57+00:00 app[web.1]:     at g (events.js:192:14)

When i run this locally, it works fine. In both cases, I am connecting to MongoHQ. Here are the relevant parts of my server.coffee:

express          = require 'express'
mongoStore       = require("connect-mongo")(express)

app.configure ->
  app.use express.errorHandler()
  app.use express.logger("dev")
  app.use express.bodyParser()
  app.use express.methodOverride()
  app.use express.cookieParser(config.cookieSecret)
  app.use express.session(
    secret: config.sessionSecret
    cookie:
      httpOnly:         true
      secure:           true
    store: new mongoStore(
      url:              config.db
      collection:       "sessions"
      auto_reconnect:   true
    )
  )
  app.use express.csrf()
  app.use express.static(config.root + "/public")
  app.use assets()
  app.use flash()

  app.use passport.initialize()
  app.use passport.session()

  app.use app.router

I am using node 0.8.14, express 3.0.3, mongoose 3.4.0, connect-mongo 0.3.2. Any help would be greatly appreciated!


Solution

  • Turns out my config file was pointing to the same db in dev and in prod. That is what caused the error.