Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Error: Error setting TTL index on collection #224

Closed
stayko opened this issue Oct 22, 2014 · 19 comments
Closed

Error: Error setting TTL index on collection #224

stayko opened this issue Oct 22, 2014 · 19 comments
Assignees
Milestone

Comments

@stayko
Copy link

stayko commented Oct 22, 2014

Hi there,

When running 'grunt' after generating my Mean.JS project with Yoeman and visiting my localhost I get the following error:

 NODE_ENV is not defined! Using default development environment

MEAN.JS application started on port 3000

/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:245
        throw message;      
              ^
Error: Error setting TTL index on collection : sessions
    at /Users/Stayko/work/meanjs/node_modules/connect-mongo/lib/connect-mongo.js:161:23
    at /Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1288:11
    at Server.Base._callHandler (/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:445:41)
    at /Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:478:18
    at MongoReply.parseBody (/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:436:20)
    at emit (events.js:95:17)
    at null.<anonymous> (/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
    at emit (events.js:98:17)
    at Socket.<anonymous> (/Users/Stayko/work/meanjs/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:439:22)
[nodemon] app crashed - waiting for file changes before starting...

I have my mongo db listening for connections in the other tab. I started it using the command 'mongod'.

Thanks

@lirantal
Copy link
Member

The error you show isn't related to NODE_ENV though, because as you can see mean.js is defaulting to the development environment anyway.
The error seems to be related to one of your mongoose models.

@stayko stayko changed the title NODE_ENV is not defined and TTL errors Error: Error setting TTL index on collection Oct 23, 2014
@stayko
Copy link
Author

stayko commented Oct 23, 2014

Ah ok, thats not a real error then. Regarding the TTL one, I haven't touched any of the models.

@lirantal
Copy link
Member

@stayko16 it seems to be an issue related to the latest version of connect-mongo/mongoose.
try to run an 'npm update' to get the latest settings which probably have this issue fixed, or change the package.json to use an older supported version of the above mentioned packages.

@stayko
Copy link
Author

stayko commented Oct 24, 2014

Ran 'npm update' and still getting the same error... I will change the versions in package.json manually but I dont understand why it doesn't work just straight out of the box..? : /

@aarosil
Copy link

aarosil commented Oct 24, 2014

Is it continual? I see that sometimes when hitting the page immediately
after express starts.
On Oct 24, 2014 6:22 AM, "Stayko Chalakov" notifications@github.com wrote:

Ran 'npm update' and still getting the same error... I will change the
versions in package.json manually but I dont understand why it doesn't work
just straight out of the box..? : /


Reply to this email directly or view it on GitHub
#224 (comment).

@stayko
Copy link
Author

stayko commented Oct 24, 2014

Yep, every time

@stayko
Copy link
Author

stayko commented Oct 24, 2014

I've switched to mean.io now..

@rschwabco
Copy link
Member

I'm not sure what the problem is - I've confirmed that the current release is stable. @stayko16 - If you're interested in solving this issue, please try and install a fresh copy of meanjs, and try again. It's hard to replicate or debug without more information about the issue...

@rschwabco
Copy link
Member

@lirantal - what issue are you referring to?

@lirantal
Copy link
Member

@roieki this one jdesboeufs/connect-mongo#65

@FREEZX
Copy link

FREEZX commented Nov 5, 2014

The issue is that app.listen is called before the database gets connected, so any requests until database connection is established will fail because the session does stuff with the database.

I fixed it by moving app.listen in the db connect callback. I'm not sure this will fix it 100%, but works for now:

// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
    if (err) {
        console.error('\x1b[31m', 'Could not connect to MongoDB!');
        console.log(err);
    }
    else{
        app.listen(config.port);
    }
});

@ryanisinallofus
Copy link

This is what we ended up doing as well. Move this into master? Seems prudent.

@ilanbiala
Copy link
Member

Yeah this is nice to have instead of what is currently in place.

@aarosil
Copy link

aarosil commented Nov 21, 2014

+1

@lirantal
Copy link
Member

I noticed that too and started a branch for fixing the bootup process entirely, so that the app can be used in tests, and can emit events properly to notify that it's ready but I think this will wait for integration with the 0.4 branch as the change will be quite extensive.

@ryanisinallofus
Copy link

Public?

We ended up having to do something like this in our tests.

https://gist.github.com/ryanrray/3f291bc66a93bfcac0cd

@amoshaviv
Copy link
Contributor

Version 0.4.0 waits for the mongodb connection before starting the express application.

warreng added a commit to warreng/runboaster that referenced this issue Feb 22, 2015
@vko-online
Copy link

This issue is still open.

server.js file

root@linux~/demo# vim server.js 

var init = require('./config/init')(),
        config = require('./config/config'),
        mongoose = require('mongoose'),
        chalk = require('chalk');

/**
 * Main application entry file.
 * Please note that the order of loading is important.
 */

// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
        if (err) {
                console.error(chalk.red('Could not connect to MongoDB!'));
                console.log(chalk.red(err));
        } else {
                var app = require('./config/express')(db);
                require('./config/passport')();
                app.listen(config.port);
                exports = module.exports = app;
                console.log('App running on port', config.port);
        }
});

// Init the express application
//var app = require('./config/express')(db);

// Bootstrap passport config
//require('./config/passport')();

// Start the app by listening on <port>
//app.listen(config.port);

// Expose app

// Logging initialization
//console.log('MEAN.JS application started on port ' + config.port);

grunt still throws error

App running on port 4000
/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
        throw message;      
              ^
Error: Error setting TTL index on collection : sessions
    at /root/demo/node_modules/connect-mongo/lib/connect-mongo.js:169:23
    at /root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1354:11
    at Server.Base._callHandler (/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
    at /root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:488:18
    at MongoReply.parseBody (/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:446:20)
    at emit (events.js:107:17)
    at null.<anonymous> (/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:207:13)
    at emit (events.js:110:17)
    at Socket.<anonymous> (/root/demo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:440:22)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)
[nodemon] app crashed - waiting for file changes before starting...

@lirantal
Copy link
Member

@vko-online looks like you're using an old version of MEAN.JS

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

No branches or pull requests

9 participants