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 · 2 comments
Open

Problem with running migrations on startup #78

SanderBreivik opened this issue Aug 21, 2023 · 2 comments

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?

@NickVandenberghe
Copy link

I went through my whole mongo db and searched all documents that included the IDocument interface in c#.
The i went through my mongodb and went through every collection that was relevant untill i found a collection that had the versionProperty that was lik to "Version: {}"

So i suggest doing the same if you encounter this issue.

This error occured for my because i tried to create a custom version property that had the same name for a limited amount of time that corrupted the Version property

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

3 participants