Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

eguvenc
Copy link

@eguvenc eguvenc commented Mar 12, 2013

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. ;)

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. ;)
@FusionAge
Copy link

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)

@eguvenc
Copy link
Author

eguvenc commented Mar 29, 2013

you need to add an auth user to your database.
use mongo shell

$ mongo

use yourdatabasename
db.addUser("root", "12345");

// AUTH TEST

db.auth("root","12345");
// 1

@FusionAge
Copy link

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?

@FusionAge
Copy link

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.

@FusionAge
Copy link

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.

@wereHamster
Copy link
Contributor

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.

@renatoargh
Copy link

I am having this issue too. connect-mongo + mongolab

@skotchio
Copy link

+1 I have the same error connect-mongo + mongolab

@cryptoquick
Copy link

I'm also having this issue with MongoHQ & connect-mongo 0.3.2.

connect-mongo.js:137 -- throw new Error('Error setting TTL index on collection : ' + s

@skotchio
Copy link

@cryptoquick
Copy link

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!

@truongsinh
Copy link

Solved by mongo-native-driver https://github.com/mongodb/node-mongodb-native/issues/966 @1.3.1

@acornejo
Copy link

+1 with latest version of mongodb driver and connect-mongo.

@thepuzzlemaster
Copy link

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?

api.use(express.session({
  store: new MongoStore({
    url: config.mongo.url
  }, function () {
    console.log("db connection open");
  })
}));

@jtremback
Copy link

Worked for me, thanks.

@hulufei
Copy link

hulufei commented Feb 15, 2014

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?

@igorauad
Copy link

igorauad commented Mar 1, 2014

vovan22, thanks for pointing this solution. This one worked for me.

@jtremback
Copy link

I used this to fix the problem, but now it is cropping up again when I try to run the app from my tests.

@jtremback
Copy link

That's really strange. I found the module connect-mongo-store does the same exact thing as this one, but works. I'll let you know if any problems come up with it as well.

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.

@lekhnath
Copy link

@thepuzzlemaster solution worked for me.

jdesboeufs added a commit that referenced this pull request Dec 24, 2014
* 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 jdesboeufs closed this Dec 24, 2014
@rahulswimmer
Copy link

Following is my code for express web server and mongoose connection:

var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var expressSession = require('express-session');
var mongoStore = require('connect-mongo')({session:expressSession});
var mongoose = require('mongoose');

require('./models/users_model.js');

var conn = mongoose.connect("mongodb://localhost:/myapp");
var app = express();

app.set("view engine","html");
app.set('views','/views');
app.engine('.html', require('ejs').__express);

app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(expressSession({
secret: 'SECRET',
cookie: {maxAge: 60601000},
store: new mongoStore({
db: mongoose.connection.db,
collection: 'sessions',
})
}));
require('./routes')(app);

app.listen(9090);

When i run this file, i get the following error:

Error: Error setting TTL index on collection : sessions
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\connect-mongo\lib
\connect-mongo.js:161:23
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\mongoose\node_mod
ules\mongodb\lib\mongodb\db.js:1430:36
at __executeInsertCommand (C:\Rahul13615\nodejseg\Project\UserAccount\node_m
odules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1829:12)
at Db._executeInsertCommand (C:\Rahul13615\nodejseg\Project\UserAccount\node
_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1930:5)
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\mongoose\node_mod
ules\mongodb\lib\mongodb\db.js:1427:14
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\mongoose\node_mod
ules\mongodb\lib\mongodb\db.js:1560:7
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\mongoose\node_mod
ules\mongodb\lib\mongodb\cursor.js:162:16
at commandHandler (C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\m
ongoose\node_modules\mongodb\lib\mongodb\cursor.js:706:16)
at C:\Rahul13615\nodejseg\Project\UserAccount\node_modules\mongoose\node_mod
ules\mongodb\lib\mongodb\db.js:1806:9
at Server.Base._callHandler (C:\Rahul13615\nodejseg\Project\UserAccount\node
_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:442:41)

Please help me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet