Node.js Mocha Unit Testing error re: Mongoose mocks with Mockgoose, "Error setting TTL index on collection : sessions" Node.js Mocha Unit Testing error re: Mongoose mocks with Mockgoose, "Error setting TTL index on collection : sessions" mongoose mongoose

Node.js Mocha Unit Testing error re: Mongoose mocks with Mockgoose, "Error setting TTL index on collection : sessions"


The "sessions" MongoDB collection is being requested here, by the Node.js Express framework's "sessions" module:

Session.save (node_modules/express-session/session/session.js:63:25)

I have been using Mockgoose to mock my Mongoose-wrapped MongoDB tables.. and it is doing its job perfectly.

The problem is that this "sessions" collection is being specified directly in the Express framework configuration, not implementing Mongoose:

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

I'll have to do my Express session mocking separately!


Not all of Mongoose is fully implemented yet. However if you can add a test case that shows this issue then I normally will focus on implementing that item over the others on my list.

https://github.com/mccormicka/Mockgoose/issues/38


I just ran into the same issue - my solution was to use express-session's memorystore option (the default when no other is specified), rather than mongodb. Really quickly, I just did this:

if (process.env.NODE_ENV === 'test') {    app.use(session({ secret: config.sessionSecret }));} else {    app.use(session({        secret: config.sessionSecret,        store: new mongoStore({            //db: db.connection.db,            mongoose_connection: db.connection,            collection: config.sessionCollection        })    }));}