Error setting TTL index during collection: session

I know that there are many questions about this problem, but any of them solved my problem. I'm actually trying to deploy my project to Heroku, which is something new for me.

My project is a node.js based on the Express API connected to the MongoDB database. When I run it locally with my database (without login / password), I do not have this error, but when I connect it to the heroku database, I get:

Error: Error setting TTL index on collection : Session <MongoError: not authorized for query on app17713548.system.indexes> 

My .json package

 "dependencies": { "express": "3.0.6", "mongodb": "1.3.19", "mongoskin": "0.5.0", "MD5": "1.0.3", "connect-session": "*", "connect-mongo": "0.3.3", "geoip-lite": "1.0.10" }, "engines": { "node": "0.8.19", "npm": "1.1.65" } 

And to connect to my database, I use MongoSkin, and the line:

 mongo.db(conf.dbLogin+':'+conf.dbPassword+'@'+conf.dbAddr+':'+conf.dbPort+'/'+conf.dbName+'?auto_reconnect=true', {w: 1}); 

Any help would be greatly appreciated!

+4
source share
2 answers

It turns out that I did not configure the session store, which was also under mongodb with the same parameters.

+1
source

Your connection string may be incorrect. Try instead:

 var mongodb = require("mongodb"); var db = new mongodb.Db(conf.dbName, new mongodb.Server(conf.dbAddr, conf.dbPort, {auto_reconnect:true}), {w:1}); db.open(function(error){ if (error){ //handle return; } db.authenticate(conf.dbLogin, conf.dbPassword, function(error){ if (error){ //handle return; } //you are now connected! }); }); 
0
source

Source: https://habr.com/ru/post/1500028/


All Articles