NodeJS, ExpressJS & PassportJS Sessions on Cloud9 connecting to Appfog Mongo - mongodb

I'm having great difficulty getting any sort of connection to MongoDB on Appfog for session storage working. I'm currently running Node Express with PassportJS and Mongoose. I've followed numerous examples and tutorials online and tried a few ODM mappers.
I must confess, I've struggled to get any sort of connection let alone, the abstracted sessions stuff working.
I've tried the SO examples here and here without success. Everytime I attempt to connect with the following code:-
var env = process.env.NODE_ENV || 'development',
config = require('./config/config')[env],
auth = require('./config/middlewares/authorization'),
mongoose = require('mongoose');
// Bootstrap db connection
mongoose.connect(config.db);
I get a:-
Error: Error setting TTL index on collection : sessions
at module.exports._get_collection (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/connect-mongo/lib/connect-mongo.js:137:23)
at Db.ensureIndex (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/mongodb/lib/mongodb/db.js:1227:28)
at Db.indexInformation (/var/lib/stickshift/514a22705973cafc85000110/app-root/data/447240/node_modules/mongodb/lib/mongodb/db.js:1371:30)
Can anyone offer any possible direction or help to get this working please?
Please ask if you need further dumps of the code here to aid a solution.
Help appreciated.

I had the same problem and it happened because I was using a partially connected db to initialize express.session().
This is what I had initially:
mongoose.connect(dbPath);
...
app.configure(function() {
...
app.use(express.session({
secret : secret,
store: new MongoStore({ db: mongoose.connection.db })
}));
...
});
The 'new MongoStore()' call happens before mongoose.connect() finishes so it uses the not-yet-connected db to set the TTL for 'sessions' and fails. I switched to "new MongoStore({ url: dbPath })" and that fixes the issue but probably results in 2 different db connections.

I was getting the same error, got past it by using the code in this question to get more error info dumped out; it helped me realize that the problem really was my user Id and password in the connect string.

I couldn't get the connection to AppFog to work. Unfortunately, AppFog themselves were unhelpful also. Therefore, I spun up a MongoHQ instance and no problems connecting at all.

Related

Error in connector: missing field `info` - Prisma Introspection (npx prisma db pull)

I have created an Express, Apollo GraphQL server which accepts requests and returns data from a MongoDB database via Prisma.
I have tested my application with a simple database from MongoDB Atlas and it all seems to work fine.
Now that I know everything works fine, I want to 'plug in' a MongoDB database which contains a lot of data already, located in my Azure portal (Cosmos DB).
I have changed the database connection string to point to this new database (a read only connection string) and now attempting to use the Introspection feature of Prisma (https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/mongodb/introspection-typescript-mongodb#introspecting-mongodb-with-prisma).
After running the npx prisma db pull --force command, I get the following error:
I can't figure out if this is an issue with my connection string, or something else.
I have also attempted to use the Read/ Write connection string but that doesn't seem to work either. I get the same error message.
There does not seem to be any information online regarding this error message other than this:
https://www.prisma.io/docs/reference/api-reference/error-reference#prismaclientvalidationerror
But I am unsure if this is at all related, because it seems to relate to creating a new record, rather than anything to do with introspection.

Mongoose : Failed to connect to mongodb instance, but mongo works fine

I'm facing a quite odd issue today.
I have a MongoDB database working just fine on a remote server, say 1.2.3.4, running on port 22222.
When I use the mongo cli to connect via the command line interface, everything works as expected:
mongo --host=1.2.3.4 --port=22222
But when I try to connect to the same instance using mongoose:
var options = {
server: {},
replset: {}
};
options.server.socketOptions = options.replset.socketOptions = { keepAlive: 120 };
mongoose.connect('mongodb://1.2.3.4:22222/test', options);
I get this error:
failed to connect to server [1.2.3.4:22222] on first connect
Anybody knows why?
FYI the all setup is in my company, which happens to have a corporate proxy.
I was thinking that maybe the proxy was the evil one in this case, but then why the mongo cli connection is working just fine?
Do you have a db called test? And have you tried omitting the options?
i.e. mongoose.connect('mongodb://1.2.3.4:22222/test');

Error trying to connect to mongolab from cdm: Error: 18 authentication fail

I'm getting this error when I try to connect to my mongolab DB.
I saw some different topics talking about this issue, but solutions they gave was:
-Add mongoDB exception in my firewall. I done it without result
-Check if I was using the mongolab.com user and password instead of the user database. That's not the problem, even I created new users.
-Check if my version of mongoDB was older than the version used by mongolab (3.x). I also specified the auth system in the command to be sure.
I tried all those answers without success. I also checked the connection with the server, and it neither was the problem. I'm going crazy.
What could be the issue?
Thanks for your attention!
It was finally a network problem. I was lucky to discover it, cause I lost many hours.

Can not access MongoDb collections on Compose.io with Mongo Client

Since last week I can not access my mongoDb collections on Compose.io using any mongo client. Client log says it is connected to DB but when I want to list collections or view document says "Collection not found!". I till can connect with terminal and do there whatever I need.
Initially I thought it is a problem with my MacOS machine, but then I tried to connect from other computers and using different clients ( Mongo-Express, MongoHub ) still no luck.
Wondering if I'm experiencing this problem alone or other compose.io clients also do ?
Tried to grant readWrite role to my mongo user as advised here (MongoDB - admin user not authorized), this does not help either.
Contacted compose.io support, but they swear that did change anything.
Any advise appreciated.
Thank you.
I was trying to connect to slave node which fails with { [MongoError: not master and slaveOk=false] name: 'MongoError' }
. Connecting with MongoClient to primary node solves the problem.

upgrade MongoHQ prevents sails-mongo to connect in prod env

I am using SailsJS 0.10.5.
I purchased a production MongoDB from Heroku and it created a variable with the new database url as follows:
mongodb://heroku:**password**#candidate.32.mongolayer.com:10485,candidate.13.mongolayer.com:10455/app123
However, when running the app in production environment only, the app fails to connect to database:
A hook (`session`) failed to load!
Could not load Connect session adapter :: connect-mongo
at new MongoStore (/app/node_modules/connect-mongo/lib/connect-mongo.js:115:19)
at validateDatabaseName (/app/node_modules/connect-mongo/node_modules/mongodb/lib
/mongodb/db.js:235:59)
at Hook.Session.initialize (/app/node_modules/sails/lib/hooks/session/index.js:20
5:37)
Error from adapter:
Error: database names cannot contain the character '.'
at new Db (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js
Note that when I copied the string locally and ran the app it worked perfectly.
I saw some workarounds suggest using Mongoose, but I want to stick to connect-mongo / sails-mongo
EDITED
I now managed to connect to the db by removing the replica set and simply add:
mongodb://heroku:**password**#candidate.32.mongolayer.com:10485/app123
However, a new error arrived:
Error: Error setting TTL index on collection : sessions
throw message;
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:700
at commandHandler (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongo
at Cursor.close (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1882:9
at Server.Base._callHandler (/app/node_modules/connect-mongo/node_modules/mongodb
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/se
It keeps crashing the app.
Ideas?
Try to setup and download mongo-uri to parse the url automatically