MongoChains.Console 0.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global MongoChains.Console --version 0.1.4
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local MongoChains.Console --version 0.1.4
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=MongoChains.Console&version=0.1.4
nuke :add-package MongoChains.Console --version 0.1.4

What is MongoChains?

MongoChains is a database migration tool for MongoDB that uses plain MongoDB javascript to transition a database from one version to another.

There is a .NET Standard Library (MongoChains), and a Console Runner (MongoChains.Console). The former is useful if you want to call MongoChains programatically but most users will probably just want to grab the console runner. MongoChains.Console is a .NET Core application so you can compile it to a native executable for your architecture if necessary.

It can also be integrated easily with build tools such as FAKE, Octopus Deploy, Teamcity etc.

MongoChains.Console Usage

USAGE: mongochains [--help] --target <connectionString> --path <path> [--targetversion <version>] [--token <key>=<value>] [--safemode]

OPTIONS:

    --target <connectionString>
                        connection string for the mongo database
    --path <path>         path to migrations files
    --targetversion <version>
                        target a specific version
    --token <key>=<value> a token to be replaced in the migrations
    --safemode            abort without running scripts if current version of db cannot be determined
    --help                display this list of options.

Getting started

Migrations files are just javascript mongo scripts. You should put the migrations into a sequence of numbered directories. Each migration should be called up.js. For example:

migrations
├───1
│       up.js
│
├───2
│       up.js
│
└───3
        up.js

If you have .NET Core 2.1 installed, you can install MongoChains as a global tool:

dotnet tool install --global MongoChains.Console

Then run it as follows:

mongochains --target "mongodb://localhost:27017" --path "/path/to/migrations"

Migrations may also contain tokens which get replaced before they are applied. This is useful when you have, for example, settings that vary between your development and production environments.

Anything in the javascript files of the form {#Key} is treated as a case-sensitive token. Before attempting to apply a migration, mongochains will ensure that you have specified values for all the tokens in that file. e.g.

mongochains --target "mongodb://localhost:27017" --path "/path/to/migrations" --token foo=bar --token buzz=bazz

By default, MongoChains will check the current version of the database by looking at the migrations collection in the admin DB, and will apply in sequence all migrations it finds that are above the current version. You can use the targetversion parameter to specify a particular version to migrate to. MongoChains migrations only go upwards, so this essentially just ignores migrations above the version you specify.

Finally, there is a safemode argument that you can specify which causes MongoChains to abort early if it cannot determine the current version of the database (that is, there is no record in the migrations collection). This is just an extra sanity check to provide reassurance in production environments.

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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
Version Downloads Last updated
0.1.5 1,063 6/11/2018
0.1.4 892 6/5/2018
0.1.3 950 6/4/2018
0.1.2-alpha 738 6/4/2018