connect-mongodb icon indicating copy to clipboard operation
connect-mongodb copied to clipboard

[email protected] TypeError: Cannot call method 'isConnected' of undefined

Open airandfingers opened this issue 11 years ago • 12 comments

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.

airandfingers avatar May 17 '13 07:05 airandfingers

I encountered a similar issue with the same error and the same solution.

matt2000 avatar May 22 '13 05:05 matt2000

+1

srour avatar May 22 '13 07:05 srour

+1

Problem persistent in [email protected]

vihang avatar May 23 '13 07:05 vihang

+1

troyth avatar May 31 '13 19:05 troyth

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.

olgmik avatar Jun 03 '13 01:06 olgmik

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.

airandfingers avatar Jun 03 '13 03:06 airandfingers

Oops, didn't mean to click "Close & Comment".

airandfingers avatar Jun 03 '13 03:06 airandfingers

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" } }

olgmik avatar Jun 03 '13 03:06 olgmik

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

airandfingers avatar Jun 03 '13 03:06 airandfingers

+1

Problem persistent in [email protected]

linhuiw avatar Jun 04 '13 01:06 linhuiw

+1

Indeed still a problem in 1.3.8

mfloryan avatar Jun 05 '13 08:06 mfloryan

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.

polidore avatar Jul 29 '13 15:07 polidore