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

refactor: Simplify accessing mongoose models #262

Merged
merged 1 commit into from
Aug 22, 2023
Merged

Commits on Aug 16, 2023

  1. refactor: Simplify accessing mongoose models

    Currently mongoose models are accessed via db connection and require a typecast.
    ```
    import { UserModel } from './user.model';
    
    const User = dbs.admin.model('User') as UserModel;
    ```
    
    Since model registry is tied to the db connection, there is no need to access it in this way.  We can just import the model (w/ proper typing) directly since it is already being exported.
    
    ```
    import { User } from './user.model';
    ```
    
    For use cases where multiple db connections are used.  Models should explicitly be registered on the appropriate connection.
    ```
    // Register model on default/admin db connection
    export const MyModel = model('MyModel', MyModelSchema);
    
    // Register model on secondary db connection
    export const OtherModel = dbs.other.model('OtherModel', OtherModelSchema);
    ```
    jrassa committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    8a4f3e2 View commit details
    Browse the repository at this point in the history