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

Problem with running migrations on startup #78

Open
SanderBreivik opened this issue Aug 21, 2023 · 1 comment
Open

Problem with running migrations on startup #78

SanderBreivik opened this issue Aug 21, 2023 · 1 comment

Comments

@SanderBreivik
Copy link

I have tried implementing migrations on startup. However, I get this error:
System.InvalidCastException: 'Unable to cast object of type 'MongoDB.Bson.BsonDocument' to type 'MongoDB.Bson.BsonString'.'
Stack trace:

  at MongoDB.Bson.BsonValue.get_AsString()
  at Mongo.Migration.Services.DocumentVersionService.GetVersionOrDefault(BsonDocument document)
  at Mongo.Migration.Migrations.Document.DocumentMigrationRunner.Run(Type type, BsonDocument document, DocumentVersion to)
  at Mongo.Migration.Migrations.Document.StartUpDocumentMigrationRunner.RunAll()
  at Mongo.Migration.Services.MigrationService.OnStartup()
  at Mongo.Migration.Services.MigrationService.Migrate()
  at Mongo.Migration.MongoMigration.Run()
  at Mongo.Migration.Startup.Static.MongoMigrationClient.Initialize(IComponentRegistry componentRegistry)
  at Mongo.Migration.Startup.Static.MongoMigrationClient.Initialize(IMongoClient client, IMongoMigrationSettings settings, IContainerAdapter containerAdapter)
  at Dialogue.Composer.Program.<>c__DisplayClass2_0.<CreateHost>b__0(HostBuilderContext context, IServiceCollection services) in C:\Dev\Microservices\Composer\Dialogue.Composer\Program.cs:line 118

What am I doing wrong here?

This is my init:

IMongoClient clientMongoDB = new MongoClient(databaseSettings.ConnectionString);

MongoMigrationClient.Initialize(clientMongoDB, new MongoMigrationSettings
{
    ConnectionString = databaseSettings.ConnectionString,
    Database = databaseSettings.DatabaseName
});
@R3DST0RM
Copy link

Were you able to solve the issue?

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