Error:Connection strategy not found!
See original GitHub issueI 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:
- Created 4 years ago
- Comments:12 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
HI, same error for me after updating to latest
connect-mongo
version (I use latestmongoose
version).Change property
db
byclient
then throw this error:Any idea to resolve this ? thanks
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.