SimpleMongoMigrations 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package SimpleMongoMigrations --version 1.0.5
                    
NuGet\Install-Package SimpleMongoMigrations -Version 1.0.5
                    
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="SimpleMongoMigrations" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleMongoMigrations" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="SimpleMongoMigrations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimpleMongoMigrations --version 1.0.5
                    
#r "nuget: SimpleMongoMigrations, 1.0.5"
                    
#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.
#addin nuget:?package=SimpleMongoMigrations&version=1.0.5
                    
Install SimpleMongoMigrations as a Cake Addin
#tool nuget:?package=SimpleMongoMigrations&version=1.0.5
                    
Install SimpleMongoMigrations as a Cake Tool

SimpleMongoMigrations

SimpleMongoMigrations is a lightweight wrapper around the official MongoDB C# Driver designed to help you manage document migrations in your MongoDB database. It supports standalone MongoDB instances, Azure CosmosDB for MongoDB, and AWS DocumentDB.

This project is inspired by and based on MongoDBMigrations.

Why a new package?

I decided to create a new NuGet package instead of using the original MongoDBMigrations or its forks, such as MongoDBMigrations (RZ version), for several reasons:

  • Dependency issues: MongoDBMigrations relies on an outdated MongoDB.Driver version (2.14.1), which prevented me from upgrading my solutions.
  • Lack of support: The original project appears to be unmaintained, with long delays in responding to issues and merging pull requests.
  • Learning opportunity: I wanted to gain hands-on experience in managing NuGet packages and setting up GitHub pipelines.

How to use

new MigrationEngine(
    "mongodb://localhost:27017", // connection string
    "TestDB", // database name
    Assembly.GetAssembly(typeof(_001_AddDefaultData)) // assembly to scan for migrations
).Run();

Unlike MongoDBMigrations, the Run method does not expect a version. All migrations will be executed unless they are marked with the Ignore attribute.

Simple migration example

See demos for .NET 6 and .NET Framework 4.7.2.

using MongoDB.Driver;
using SimpleMongoMigrations.Abstractions;
using SimpleMongoMigrations.Attributes;
using SimpleMongoMigrations.ConsoleAppNet6.Models;

namespace SimpleMongoMigrations.Tests.Migrations
{
    [Version("0.0.3")] // You can also use numbers for versions, such as 1, 2, 3, etc.
    [Name("Adds a unique index by name")] // Optional text description
    [Ignore] // Ignore this migration, for instance, if it causes issues
    public class _003_AddIndexByName : IMigration
    {
        public void Up(IMongoDatabase database)
        {
            database.GetCollection<City>(nameof(City)).Indexes.CreateOne(new CreateIndexModel<City>(
                Builders<City>.IndexKeys.Ascending(x => x.Name),
                new CreateIndexOptions
                {
                    Unique = true
                }));
        }
    }
}

Note that the IMigration interface does not include a Down method. This means you cannot roll back migrations or downgrade your database.

Migration history

SimpleMongoMigrations maintains migration history in a way that is compatible with MongoDBMigrations. If you are already using MongoDBMigrations, you do not need to make any changes to your database — only minor code adjustments may be required to refactor your migrations.

Below is a sample entry created in the _migrations collection:

{
    "_id" : ObjectId("6828faf9642d86f79f782e4f"),
    "n" : "Adds a unique index by name",
    "v" : "0.0.3",
    "d" : true,
    "applied" : ISODate("2025-05-17T21:09:13.355+0000")
}

Transactions

Transactions are not supported at the moment. However, support for transactions is planned for a future release.

License

SimpleMongoMigrations is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
1.0.14 0 5/27/2025
1.0.13 29 5/26/2025
1.0.12 33 5/26/2025
1.0.11 36 5/26/2025
1.0.10 39 5/26/2025
1.0.9 29 5/25/2025
1.0.8 32 5/25/2025
1.0.7 33 5/25/2025
1.0.6 42 5/25/2025
1.0.5 125 5/18/2025
1.0.4 125 5/18/2025
1.0.3 125 5/18/2025
1.0.2 89 5/17/2025
1.0.1 86 5/17/2025
1.0.0 85 5/17/2025