Hello, I am working on a .NET 6 project that includes a background service. I have configured the migration in the startup as shown below. However, I have a problem: the background service tries to access the database before it is ready. This happens when the migration takes longer than usual to set up MongoDB. How can I ensure that the background service waits for the migration to finish before performing any database operations?
services
.AddMigration(new MongoMigrationSettings
{
Database = "blabla",
ConnectionString = config.GetConnectionString("MongoDb"),
DatabaseMigrationVersion = new DocumentVersion(1, 0, 0)
});