Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reuse an exisiting native mongo instance #461

Open
Mohamed-kamel91 opened this issue Aug 7, 2022 · 0 comments
Open

Can't reuse an exisiting native mongo instance #461

Mohamed-kamel91 opened this issue Aug 7, 2022 · 0 comments

Comments

@Mohamed-kamel91
Copy link

hi,
I am trying to connect express session to my native mongo store by reusing the existing mongo client instance, but no matter how much i try, it never seem to work at all.
when i run my app , i always end up with this error

Assertion failed: You must provide either mongoUrl|clientPromise|client in options
Error: Cannot init client. Please provide correct options
at new MongoStore (D:\code\clients\development\Trendy-Toys\server\node_modules\connect-mongo\src\lib\MongoStore.ts:196:13)
at Function.create (D:\code\clients\development\Trendy-Toys\server\node_modules\connect-mongo\src\lib\MongoStore.ts:214:12)
at Object. (D:\code\clients\development\Trendy-Toys\server\src\config\sessionStore.ts:11:33)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module.m._compile (D:\code\clients\development\Trendy-Toys\server\node_modules\ts-node\src\index.ts:1371:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions. [as .ts] (D:\code\clients\development\Trendy-Toys\server\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)

This my express session in app.js file:

import sessionStore from './config/sessionStore';

const sessionOptions = {
  secret: env.SESSION_SECRET,
  resave: false,
  saveUninitialized: true,
  store: sessionStore,
  cookie: {
    secure: false,
    name: "session_id",
    sameSite: false,
    httpOnly: true,
    maxAge:  10 * 1000,
  },
};

// set express session store
app.use(session(sessionOptions));

This is sessionStore file:
I am importing my mongodb instance from a seperate file

import MongoStore from 'connect-mongo';
import env from '.';
import { client } from '../database/db';

const sessionStore = MongoStore.create({
  client,
  collectionName: "sessions",
});

export default sessionStore;

versions:

  • express: 4.17.1
  • express-session": 1.17.3
  • connect-mongo: 4.6.0
  • mongodb: 4.1.1

I'd apprecite if anyone can help me with this issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant