mongo-connect(session) 的 mongo-connect 错误 [英] mongo-connect error with mongo-connect(session)
问题描述
在四处搜索之后,我在我的code
中找不到关于此错误的任何解决方案或错误.我的 app.js
文件包含在我的节点 JS 应用程序中,并带有 mongo-connect
声明:
After searching around about it, I can't find any solution or mistake in my code
about this error. I've got my app.js
files inside my node JS application with the mongo-connect
declaration :
const MongoStore = require('connect-mongo')(session)
我遇到了这个错误:
TypeError: 类构造函数 MongoStore 不能在没有的情况下被调用'新的'在对象.(/Users/souhailmohamed/project/devops/story website/app.js:11:20)在 Module._compile (internal/modules/cjs/loader.js:1063:30)在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)在 Module.load (internal/modules/cjs/loader.js:928:32)在 Function.Module._load (internal/modules/cjs/loader.js:769:14)在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)在内部/main/run_main_module.js:17:47
TypeError: Class constructor MongoStore cannot be invoked without 'new' at Object. (/Users/souhailmohamed/project/devops/story website/app.js:11:20) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47
下面是我的 app.use
代码:
app.use(session({
secret: 'story book',
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))
我非常了解
const MongoStore = require('connect-mongo')(session)
但我不明白这个错误.但它来自 traversy media LinK 的 youtube 教程
but I didn't understand the error. But it's from a tutorial from youtube by traversy media LinK
推荐答案
我在我的代码中遇到了同样的问题并使用这个解决了它:
I had the same problem in my code and solved it using this:
const MongoDbStore = require('connect-mongo');
从 require 语句中删除 (session) 并像这样更新 app.use():
Remove (session) from the require statement and update the app.use() like this:
// Session Config
app.use(
session({
secret: 'story book',
resave: false,
saveUninitialized: false,
store: MongoDbStore.create({
mongoUrl: YourDatabaseURL
})
})
);
这篇关于mongo-connect(session) 的 mongo-connect 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!