question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error:Connection strategy not found!

See original GitHub issue

I was trying to use MongoStore with native mongodb driver. This is how my configuration looks liks

//  imports
const express = require('express');
const session = require('express-session');
const mongoClient = require('mongodb').MongoClient;
const MongoStore = require('connect-mongo')(session);

//  express app
const app = express();

//  connecting to mongodb

mongoClient.connect('url', options, (err, client) => {
 if (err) {
    console.log('MongoDB connection error.');
    return;
  }
//  connection successful

  console.log(client.isConnected(), 'isConnected'); //getting 'true'

//   setup express session once connected to db

  app.use(session({
    name: 'mysession',
    store: new MongoStore({ client }),
    secret: 'SESSION_SECRET',
    touchAfter: 24 * 3600,
    resave: false,
    saveUninitialized: false,
    cookie: { maxAge: 1000 * 60 * 15 },
  }));

// finally listening to port 8080

 app.listen(8080,console.log('listening'));
  });

I’m connected to the database successfully but when I pass the instance of MongoClient to the MongoStore I’m getting an error saying Connection strategy not found .

I also looked into the source code to see the options MongoStore is accepting and it has these two checks options.client && options.client.isConnected() before handling the core-mongo connection which are true in this case.

I’m not sure what I’m doing wrong here. It’s working fine with the mongoose though.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
popodcommented, Nov 6, 2019

HI, same error for me after updating to latest connect-mongo version (I use latest mongoose version).

Change property db by client then throw this error:

TypeError: mongoose.connection.isConnected is not a function

Any idea to resolve this ? thanks

0reactions
stale[bot]commented, Oct 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Connection strategy not found MongoDB - Stack Overflow
The 'db:' parameter you are using is expecting a MongoDB driver connect, not a url to a Mongo Database. For that, you should...
Read more >
Not sure why localhost isn't working (Example) - Treehouse
I am getting this error in the command line when I run "Nodemon app.js" ... new Error('Connection strategy not found'); ^ Error: Connection...
Read more >
Error: Connection strategy not found MongoDB-mongodb
here is a simple connection to use express session store, it keeps banging out this error even though the text is right from...
Read more >
Error: Connection strategy not found - 51CTO博客
8. Express4中,MongoStore必须要设置url属性,. 就是mongodb的链接url:mongodb://127.0.0.1/dbname. 设置上就好了。
Read more >
connect-mongo:Error: Connection strategy not found
connect-mongo:Error: Connection strategy not found ... 在此感谢! ... 版权声明:本文为CSDN博主「weixin_34402408」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found