Database.MongoDB.Migration 2.48.0

dotnet add package Database.MongoDB.Migration --version 2.48.0                
NuGet\Install-Package Database.MongoDB.Migration -Version 2.48.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Database.MongoDB.Migration" Version="2.48.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Database.MongoDB.Migration --version 2.48.0                
#r "nuget: Database.MongoDB.Migration, 2.48.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Database.MongoDB.Migration as a Cake Addin
#addin nuget:?package=Database.MongoDB.Migration&version=2.48.0

// Install Database.MongoDB.Migration as a Cake Tool
#tool nuget:?package=Database.MongoDB.Migration&version=2.48.0                

MongoDBMigration

MongoDBMigration is a simple library open-sorce that facilitates MongoDB database migration through a version-based migration system. It provides a convenient way to manage and execute MongoDB database migrations in a controlled and organized manner.

Features

  • Supports multiple MongoDB instances
  • Automatically creates migration indexes
  • Validates migration versions to avoid duplicates

Installation

  • This implation is based using the official library MongoDB.Driver
  • Use NuGet to install the MongoDBMigration library into your project. You can use the following command in the Package Manager Console: Nuget
Install-Package Database.MongoDB.Migration

Configurations

The MongoDBMigration library is easy to use and requires just a few configurations. Follow the steps below to get started:

Configure your MongoDB database connection:

IMongoClient mongoClient = new MongoClient("mongodb://localhost:27017");
IMongoDatabase mongoDatabase = mongoClient.GetDatabase("your-database");
serviceCollection.AddMongoMigration(mongoDatabase);

OR, you can use some parameters to configure

IMongoClient mongoClient = new MongoClient("mongodb://localhost:27017");
IMongoDatabase mongoDatabase = mongoClient.GetDatabase("your-database");
serviceCollection.AddMongoMigration(mongoDatabase, x =>
        {
            x.MigrationAssembly = typeof(SomeAssemblyWhereWilBeYourMigrations).Assembly;
            x.Namespace = typeof(IfYouWillUseJustASpecifyNamespace).Namespace; //optional
        });

If you Will need a instance using another database, you can do this.


IMongoClient mongoClient = new MongoClient("mongodb://localhost:27017");
IMongoDatabase mongoDatabase = mongoClient.GetDatabase("your-database");
IMongoDatabase mongoDatabase2 = mongoClient.GetDatabase("your-another-database");
serviceCollection.AddMongoMigration(mongoDatabase, x =>
        {
            x.MigrationAssembly = typeof(SomeAssemblyWhereWilBeYourMigrations).Assembly;
            x.Namespace = typeof(IfYouWillUseJustASpecifyNamespace).Namespace; //optional
        }).AddMongoMigration<ExampleMultiInstance>(mongoDatabase, x =>
        {
            x.MigrationAssembly = typeof(SomeAssemblyWhereWilBeYourMigrations).Assembly;
            x.Namespace = typeof(AnotherNamespace).Namespace; //optional
        });

this ExampleMultiInstance will need be a class, that implement a IMongoMultiInstance

public class ExampleMultiInstance : IMongoMultiInstance
{
    
}

And it's done. When your serviceProvider was created, will run a HostedService that will execute your migrations.

How to create Migration

  • Create your migrations by inheriting from the BaseMigration class and implement the Migrate method to perform the database changes:
public class ExampleMigration : BaseMigration
{
    public override int Version => 1; //required 
    public override bool IsUp => true; //required, will inform if will need to downgrade your migration 
    //False - Will do a downgrade if the migration was already applyed
    //True - Will apply the migration
    
    public override async Task UpAsync(IMongoDatabase database, CancellationToken cancellationToken = default)
    {
        // Your migration logical here
    }

    public override async Task DownAsync(IMongoDatabase database, CancellationToken cancellationToken = default)
    {
        // Your migration logical here
    }
}

Now you are ready to use the MongoDB database migration system provided by MongoDBMigration.

Contribution

Contributions are welcome! If you encounter an issue, have any ideas, or want to add a new feature, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Contact

If you have any questions, suggestions, or just want to get in touch, you can find me on:

Buy me a coffee?

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.48.0 191 7/17/2023
2.40.0 160 7/16/2023
2.35.0 145 7/15/2023
1.34.0 158 7/15/2023
1.33.0 160 7/13/2023
1.27.0 171 7/13/2023
1.26.0 153 7/13/2023
1.25.0 177 7/9/2023
1.24.0 167 7/9/2023
1.23.0 145 7/9/2023
1.22.0 150 7/9/2023
1.21.0 166 7/8/2023
1.20.0 160 7/8/2023
1.19.0 169 7/8/2023
1.0.18 172 7/8/2023
1.0.0 164 7/8/2023