javascript - The problem of using MongoDb to store session data in Node and Express development. According to the book, the following questions appeared. I have been searching for a long time and cannot find the answer. I would like to ask everyone for advice.
世界只因有你
世界只因有你 2017-06-10 09:48:01
0
2
881

Error using MongoDb to store session data

Code:
// Use mongoDb to store session data

var MongoSessionStore = require('session-mongoose')(require('connect'));
var sessionStore = new MongoSessionStore({url: credentials.mongo.production.connectionString});

app.use(require('cookie-parser')(credentials.cookieSecret));
// store是会话存储的实例,默认为一个MemoryStore的实例
app.use(require('express-session')({ store: sessionStore }));

An error occurred during operation

C:\Program Files\nodejs\projects\meadowlark\node_modules\session-mongoose\index.
js:266
    })(connect.session.Store);
                      ^

TypeError: Cannot read property 'Store' of undefined
    at module.exports (C:\Program Files\nodejs\projects\meadowlark\node_modules\
session-mongoose\index.js:266:23)
    at Object.<anonymous> (C:\Program Files\nodejs\projects\meadowlark\meadowlar
k.js:190:52)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:505:3

I searched Baidu and Google for a long time, and tried require('session-mongoose')(require('express')); and so on, but it still failed. I also tried require('connect-mongo')( require('express'));, I have been confused for a long time, so I specifically asked the experts.


grateful!

世界只因有你
世界只因有你

reply all(2)
黄舟

The answer is in the comments
Also, if you encounter any problems, try to read the README.md in node_modules. There are a lot of examples in it. I hope it will be helpful to beginners like me who are stuck!

迷茫

Here is a project for express and mongodb https://github.com/treeandgra...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template