0

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

3
  • Please give a minimal reproducible example. I'd recommend taking the tour and reading How to Ask. Commented May 22, 2022 at 18:20
  • Please add the code snippet from index.js file as well. Commented May 22, 2022 at 18:32
  • @DusayantaPrasad I have added the link, please review it. Commented May 23, 2022 at 1:33

1 Answer 1

1

Hi was facing a similar issue while connecting MongoDB session in nodejs.

Steps to fix:

  1. update the mongoose and connect-mongo package.

  2. update the require statement. Remove (session) from it. const MongoStore = require('connect-mongo');

  3. update the code

    app.use(
     session({
     secret: 'story book',
     resave: false,
     saveUninitialized: false,
     store: MongoStore.create({
         mongoUrl: YourDatabaseURL
      })
     })
    );
    
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.