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

How to know the migration version of the database? #59

Open
alexiaprada opened this issue Oct 28, 2022 · 1 comment
Open

How to know the migration version of the database? #59

alexiaprada opened this issue Oct 28, 2022 · 1 comment

Comments

@alexiaprada
Copy link

Hi, I want to get the version of the database in a status controller in netcore. How can I find out in what version is the database?

@ssteiner
Copy link

ssteiner commented Aug 5, 2024

have you tried IOC-ing the IDatabaseVersionService? It's a public interface, and it implements the GetLatestDatabaseVersion method which the project itself uses to determine the version. Add the following two parameters to your controller constructor:

public MyControllerConstructor(IMongoDatabase db, IDatabaseVersionService versionService, ... other constructor parameters here)

Then your controller method to get the version would look something like this:

    public IActionResult GetVersion()
    {
        DocumentVersion dbVersion = versionService.GetLatestDatabaseVersion(db);
        // now do something with it
    }

The IDatabaseVersionService gets registered when calling AddMigrations, and if you follow the .net Core setup as per the readme, you also have the IMongoDatabase so you should be good to go.

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

2 participants