Skip to content

Await connection #107

Open
Open
@MickL

Description

@MickL

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);
    });
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions