Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot call method 'findOne' of null at MongoStore.get #48

Open
erhangundogan opened this issue Mar 17, 2012 · 11 comments
Open

Comments

@erhangundogan
Copy link

Hi.
I'm using [email protected] and getting "TypeError: Cannot call method 'findOne' of null at MongoStore.get"
after updated to [email protected], [email protected]. I guess your mongodb version 0.9.7 is rather old one.

@danmactough
Copy link

Yup. Ditto here. It seemed completely broken. Turned out I was not calling the constructor properly. Old example code strikes again.

I thought I should use new mongoStore({ db: db }) where the 2nd db is the db global created when I fire up Mongoose. But that's not right. Instead, I tried new mongoStore({ url: myDbUrl }) and it works.

@hunterloftis
Copy link

Caught me as well. Old, confusing docs.

@kof
Copy link

kof commented May 31, 2012

same prob, any news here?

@andreek
Copy link

andreek commented Jun 3, 2012

@kof the solution by danmactough with db url as parameter works for me, too.

@kof
Copy link

kof commented Jun 3, 2012

my issue was, that connection was used before it is ready, after I started to use a callback it stoped throw errors. I suppose queries will not be queued until connection is established like in mongoose.

@JerryLuke
Copy link

Will this method work when using MongoDB in a replicaset and the URL specifies multiple hosts? I did not see any indication in the code that it does.

@CrabBot
Copy link

CrabBot commented Aug 29, 2012

Stumbled across this obviously using Mongoose and unsure of where the expected connect-mongodb db object is. The proposed solution to use the db url, would open 2 connections as far as I can tell. Ideally there'd be a way to get the expected db object out of mongoose and reuse it rather than setting up a separate connection.

Will follow-up if I find it.

@lern
Copy link

lern commented Oct 1, 2012

@CrabBot I also wanted to use an existing connection rather than creating a separate one and the solution that worked for me was to use db: mongoose.connection.db in mongoStore. I also had to ensure that the database connection was established first before setting up the session store. Here's what I did:

var mongoose = require('mongoose');
var mongoStore = require('connect-mongodb');
db = mongoose.connect(DB_URI);

mongoose.connection.on('open', function() {
  app.use(express.session({
    store: new mongoStore({
      db: mongoose.connection.db,
      collection : 'sessions'
    })
  }));
});

@CrabBot
Copy link

CrabBot commented Oct 1, 2012

@lern Thanks. I'll check that out.

@stefanszymanski
Copy link

@lern
Thank you so much!
After hours of headache it finally works :)

@CrabBot
Copy link

CrabBot commented Dec 20, 2012

Just a follow-up, @lern's solution works.

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

No branches or pull requests

9 participants