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

Await connection #107

Open
MickL opened this issue Jan 24, 2023 · 0 comments
Open

Await connection #107

MickL opened this issue Jan 24, 2023 · 0 comments

Comments

@MickL
Copy link

MickL commented Jan 24, 2023

I noticed that when creating a new MongoDBStore new MongoDBStore({ ... }) the MongoDB connection gets established async and is not awaited. Following the example from the readme when server = app.listen(3000); is called, the MongoDB connection is probably not yet established and store.client is undefined.

In my opinion new MongoDBStore() should return a promise that can be awaited OR there should be a separate function for connecting:

const store = await new MongoDBStore({ ... });

OR:

const store = new MongoDBStore({ ... });
await store.connect();

Current workaround:

const store = new MongoDBStore({ ... });

await new Promise((resolve) => {
    store.on('connected', () => {
      resolve(undefined);
    });
  });
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