connect-mongodb
connect-mongodb copied to clipboard
[email protected] TypeError: Cannot call method 'isConnected' of undefined
This error occurs consistently upon creating the MongoStore:
.../node_modules/mongodb/lib/mongodb/connection/server.js:208
return this.connectionPool.isConnected();
^
TypeError: Cannot call method 'isConnected' of undefined
at Server.isConnected (.../node_modules/mongodb/lib/mongodb/connection/server.js:208:30)
at new MongoStore (.../node_modules/connect-mongodb/lib/connect-mongodb.js:90:21)
Worked around by forcing mongodb to verstion 1.3.4.
I encountered a similar issue with the same error and the same solution.
+1
+1
How do you force mongodb to verstion 1.3.4? I am working with someone's example and having this error. I don't see where I can make this change. In which file of my app? An d what exactly should the line be? Thank you in advance.
The mongodb folder in the node_modules folder is what's used by the app. Typically the node_modules folder is populated by running the "npm install" command, which reads the dependencies from a file called package.json.
Assuming you're following this typical dependency-management style, modify your package.json so that the version of mongodb depended on is set to "1.3.4" (rather than "~1.3.x" or "1.3.5"), then run "npm install."
For more information on npm, see this (somewhat-dated) series of Nodejitsu blog posts.
Oops, didn't mean to click "Close & Comment".
Thank you for your answer, Airandfingers, but my package.json doesn't have mongodb in it. Below is the contents of the package file. Meanwhile though, I somewhat fixed the issue by changing my express.session lines of code to this:
var MongoStore = require('connect-mongo')(express); app.use(express.session({ store: new MongoStore({ url: process.env.MONGOLAB_URI }), secret: process.env.COOKIEHASH }));
Here is my package.json file: { "name": "dwd-nodejs-passportjs", "version": "0.0.1",
"dependencies": { "express": "3.x", "hogan-express" : "0.3.3", "mongoose" : "3.5.4", "moment" : "1.7.2", "passport": "0.1.x", "consolidate": "latest", "ejs" : "latest", "passport-local": "0.1.x", "passport-local-mongoose": "0.2.0", "connect-mongo" : "0.3.x", "aws-sdk" : "v0.9.8-pre.9" },
"engines" : { "node" : "0.8.x", "npm" : "1.1.x" } }
Hm, it looks like you're using connect-mongo instead of connect-mongodb. That's a mistake I've seen a few times in this repo's issues (I sometimes get confused, myself.)
Here's an excerpt from my code, for reference:
var MongoStore = require('connect-mongodb') //used as our session store
, mongodb = require('mongodb')
, db = new mongodb.Db(db_config.DB_NAME, server_config, { w: -1 });
, session_store = new MongoStore({ db: db, username: 'user', password: 'password });
+1
Indeed still a problem in 1.3.8
The better work around is to just connect to your mongodb object before you pass it to conenct-mongodb.
I have raised an issue with mongodb API to fix this better.