Reputation: 9
While running node app.js
the Express server is connecting properly and the MongoDB is connecting correctly, but I am facing a problem in the node module as mentioned above.
The complete log is pasted below:
throw new TypeError("expecting a function but got " + util.classString(fn));
^
TypeError: expecting a function but got [object Undefined]
at Function.Promise.promisify (D:\Project\DD-NODEJS\node_modules\bluebird\js\release\promisify.js:270:15)
at D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:155:56
at Array.forEach (<anonymous>)
at MongoStore.setCollection (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:154:67)
at MongoStore.handleNewConnectionAsync (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:120:18)
at NativeConnection.<anonymous> (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:91:72)
at Object.onceWrapper (node:events:509:28)
at NativeConnection.emit (node:events:402:35)
at NativeConnection.Connection.onOpen (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:647:8)
at _setClient (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:895:8)
at D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:797:7
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\utils.js:423:9
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\mongo_client.js:130:17 at connectCallback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:29:9)
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:80:9
at Object.callback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\sdam\topology.js:230:17)
To view Index.js Click Here To view App.js Click Here
Upvotes: 0
Views: 683
Reputation: 104
Hi was facing a similar issue while connecting MongoDB session in nodejs.
Steps to fix:
update the mongoose and connect-mongo package.
update the require statement. Remove (session) from it. const MongoStore = require('connect-mongo');
update the code
app.use(
session({
secret: 'story book',
resave: false,
saveUninitialized: false,
store: MongoStore.create({
mongoUrl: YourDatabaseURL
})
})
);
Upvotes: 1