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
Update connect-mongo.js #58
Conversation
if user not created an auth for database ( especially work on localhost ) mongodb returns an TTL error because of it couldn't write to database via ensureIndex(), console.log(err) help to us to see mongodb error. ;)
I'm starting to see this error randomly, and have to restart to clear it. I'm using mongolab as my mongodb provider, and nodemon to restart the app when I save files. Error: Error setting TTL index on collection : sessions at /srv/node/chat/node_modules/connect-mongo/lib/connect-mongo.js:137:23 at /srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1227:28 at /srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1371:30 at /srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:156:22 at /srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:611:39 at Cursor.close (/srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:939:5) at commandHandler (/srv/node/chat/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:611:21) at g (events.js:175:14) at EventEmitter.emit (events.js:106:17) |
you need to add an auth user to your database. $ mongo
// AUTH TEST
|
Question: I'm connecting via standard URI: mongdob://[username]:[password]@[server]:[port]/[instance]-- since I'm reading/writing to the sessions collection, doesn't that mean the username/password I'm using is already auth'd? |
I did the db.auth() as you instructed just to be safe...but it still appeared. I tested this by re-saving a file (so that nodemon would detect the change & restart the service) -- still get the TTL error, whether I run it via nodemon or manually. |
I think this was related to MongoLab, I've been beating up on this with my local mongodb install and I haven't seen the issue reoccur. Sorry for any false alarms, but if anyone searches and they're using MongoLab, that was my issue. |
I don't use authentication and I'm seeing this error as well. I can trigger it reliably by trying to open the webpage very quickly after starting the server. If I wait two seconds before reloading the webpage everything works. The actual error is: no open connections at Db._executeQueryCommand (node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1705). I'm using connect-mongo version 0.3.2. |
I am having this issue too. connect-mongo + mongolab |
+1 I have the same error connect-mongo + mongolab |
I'm also having this issue with MongoHQ & connect-mongo 0.3.2.
|
Here is the solution of the issue: http://stackoverflow.com/questions/15748644/nodejs-expressjs-passportjs-sessions-on-cloud9-connecting-to-appfog-mongo |
Ah yeah, I see what's happening-- at least, in my code. I'm feeding the wrong database object into my express session middleware. Thanks! |
Solved by mongo-native-driver https://github.com/mongodb/node-mongodb-native/issues/966 @1.3.1 |
+1 with latest version of mongodb driver and connect-mongo. |
I've been having this exact same problem using MongoLab. I've found a fix though! I add a callback to my express.session method, and then the TTL error goes away! I take the callback out, and it comes back every time I make my first call after firing up my node app. Perhaps this will resolve things for you too?
|
Worked for me, thanks. |
Still have this error when I tried to run a test with supertest. I want to test a register process protected by csrf, here is the code: var request = require('supertest');
var agent = request.agent(app);
var user = { email: 'test@gmail.com', password: 'dummy' };
agent
.get('/signup')
.end(function(err, res) {
// Get hidden _csrf value
var token = res.text.match(/_csrf.*?value=['"](.*?)['"]/)[1];
user._csrf = token;
agent.saveCookies(res);
agent
.post('/signup')
.send(user)
.end(done); Any tips? |
vovan22, thanks for pointing this solution. This one worked for me. |
I used this to fix the problem, but now it is cropping up again when I try to run the app from my tests. |
That's really strange. I found the module EDIT: So, I was getting a completely different error with that other module, switched back to this one, and everything works fine. I should probably just learn how these work myself at this point. |
@thepuzzlemaster solution worked for me. |
* 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
Following is my code for express web server and mongoose connection: var express = require('express'); require('./models/users_model.js'); var conn = mongoose.connect("mongodb://localhost:/myapp"); app.set("view engine","html"); app.use(bodyParser.urlencoded({extended:true})); app.listen(9090); When i run this file, i get the following error: Error: Error setting TTL index on collection : sessions Please help me! |
if user not created an auth for database ( especially work on localhost ) mongodb returns an TTL error because of it couldn't write to database via ensureIndex(), console.log(err) help to us to see mongodb error. ;)