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

feat: add lazy connection configuration option #1773

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

zaawee
Copy link
Contributor

@zaawee zaawee commented Apr 25, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

The current behavior of the module is that when the connection is injected it also connects to the database. This is caused by the use of .asPromise() when creating the connection.

This caused issues for us when we tried starting a service without having mongo up and running.

Issue Number: N/A

What is the new behavior?

This PR adds a configuration option for the module that enables the use of the module without it connecting automatically when the connection is injected.

The new config interface is:

export interface MongooseModuleOptions
  extends ConnectOptions,
    Record<string, any> {
  uri?: string;
  retryAttempts?: number;
  retryDelay?: number;
  connectionName?: string;
  connectionFactory?: (connection: any, name: string) => any;
  connectionErrorFactory?: (error: MongooseError) => MongooseError;
  lazyConnection?: boolean;
}

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@zaawee
Copy link
Contributor Author

zaawee commented Jun 7, 2023

Hey @kamilmysliwiec,
This PR has been sitting here for quite a while, and I'm wondering if there's anything I should fix or do in order to help this merge
Thanks

@kamilmysliwiec kamilmysliwiec changed the base branch from master to 10.0.0 June 12, 2023 12:36
@kamilmysliwiec kamilmysliwiec merged commit 7e265f0 into nestjs:10.0.0 Jun 12, 2023
@kamilmysliwiec
Copy link
Member

lgtm

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

Successfully merging this pull request may close these issues.

2 participants