4

I'm having great difficulty getting any sort of connection to MongoDB on Appfog for session storage working. I'm currently running Node Express with PassportJS and Mongoose. I've followed numerous examples and tutorials online and tried a few ODM mappers.

I must confess, I've struggled to get any sort of connection let alone, the abstracted sessions stuff working.

I've tried the SO examples here and here without success. Everytime I attempt to connect with the following code:-

var env = process.env.NODE_ENV || 'development',
    config = require('./config/config')[env],
    auth = require('./config/middlewares/authorization'),
    mongoose = require('mongoose');

// Bootstrap db connection
mongoose.connect(config.db);

I get a:-

Error: Error setting TTL index on collection : sessions
    at module.exports._get_collection (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/connect-mongo/lib/connect-mongo.js:137:23)
    at Db.ensureIndex (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/mongodb/lib/mongodb/db.js:1227:28)
    at Db.indexInformation (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/mongodb/lib/mongodb/db.js:1371:30)

Can anyone offer any possible direction or help to get this working please?

Please ask if you need further dumps of the code here to aid a solution.

Help appreciated.

Community
  • 1
  • 1
dooburt
  • 3,010
  • 10
  • 41
  • 59

3 Answers3

1

I had the same problem and it happened because I was using a partially connected db to initialize express.session().

This is what I had initially:

mongoose.connect(dbPath);
...
app.configure(function() {
  ...
  app.use(express.session({
    secret : secret,
    store: new MongoStore({ db: mongoose.connection.db })
  }));
  ...
});

The 'new MongoStore()' call happens before mongoose.connect() finishes so it uses the not-yet-connected db to set the TTL for 'sessions' and fails. I switched to "new MongoStore({ url: dbPath })" and that fixes the issue but probably results in 2 different db connections.

Satish
  • 121
  • 3
0

I was getting the same error, got past it by using the code in this question to get more error info dumped out; it helped me realize that the problem really was my user Id and password in the connect string.

Community
  • 1
  • 1
-1

I couldn't get the connection to AppFog to work. Unfortunately, AppFog themselves were unhelpful also. Therefore, I spun up a MongoHQ instance and no problems connecting at all.

dooburt
  • 3,010
  • 10
  • 41
  • 59