EphemeralMongo.Core 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EphemeralMongo.Core --version 0.1.0                
NuGet\Install-Package EphemeralMongo.Core -Version 0.1.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="EphemeralMongo.Core" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EphemeralMongo.Core --version 0.1.0                
#r "nuget: EphemeralMongo.Core, 0.1.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 EphemeralMongo.Core as a Cake Addin
#addin nuget:?package=EphemeralMongo.Core&version=0.1.0

// Install EphemeralMongo.Core as a Cake Tool
#tool nuget:?package=EphemeralMongo.Core&version=0.1.0                

EphemeralMongo - temporary and disposable MongoDB for integration tests and local debugging

build

EphemeralMongo is a set of three NuGet packages wrapping the binaries of MongoDB 4, 5 and 6. Each package targets .NET Standard 2.0, which means you can use it with .NET Framework 4.5.2 up to .NET 6 and later.

The supported operating systems are Linux, macOS and Windows on their x64 architecture versions only. Each package provides access to:

  • Multiple ephemeral and isolated MongoDB databases for tests running,
  • A quick way to setup a MongoDB database for a local development environment,
  • mongoimport and mongoexport tools in order to export and import collections.

This project is very much inspired from Mongo2Go but contains several improvements:

  • Support for multiple major MongoDB versions that are copied to your build output,
  • There is a separate NuGet package for each operating system and MongoDB version so it's easier to support new major versions,
  • The latest MongoDB binaries are safely downloaded and verified by GitHub actions during the build or release workflow, reducing the Git repository size,
  • There's less chances of memory, files and directory leaks. The startup is faster by using C# threading primitives such as ManualResetEventSlim.
  • The CI tests the generated packages against .NET 4.6.2, .NET Core 3.1 and .NET 6 using the latest GitHub build agents for Ubuntu, macOS and Windows.

Downloads

Package Description Link
EphemeralMongo4 All-in-one package for MongoDB 4.4.15 on Linux, macOS and Windows nuget
EphemeralMongo5 All-in-one package for MongoDB 5.0.10 on Linux, macOS and Windows nuget
EphemeralMongo6 All-in-one package for MongoDB 6.0.0 on Linux, macOS and Windows nuget

Usage

Use the static MongoRunner.Run() method to create a disposable instance that provides access to a MongoDB connection string, import and export tools:

// All properties below are optional. The whole "options" instance is optional too!
var options = new MongoRunnerOptions
{
    UseSingleNodeReplicaSet = true, // Default: false
    StandardOuputLogger = line => Console.WriteLine(line), // Default: null
    StandardErrorLogger = line => Console.WriteLine(line), // Default: null
    DataDirectory = "/path/to/data/", // Default: null
    BinaryDirectory = "/path/to/mongo/bin/", // Default: null
    ConnectionTimeout = TimeSpan.FromSeconds(10), // Default: 30 seconds
    ReplicaSetSetupTimeout = TimeSpan.FromSeconds(5), // Default: 10 seconds
    AdditionalArguments = "--quiet", // Default: null
};

// Disposing the runner will kill the MongoDB process (mongod) and delete the associated data directory
using (var runner = MongoRunner.Run(options))
{
    var database = new MongoClient(runner.ConnectionString).GetDatabase("default");

    // Do something with the database
    database.CreateCollection("people");

    // Export a collection. Full method signature:
    // Export(string database, string collection, string outputFilePath, string? additionalArguments = null)
    runner.Export("default", "people", "/path/to/default.json");

    // Import a collection. Full method signature:
    // Import(string database, string collection, string inputFilePath, string? additionalArguments = null, bool drop = false)
    runner.Import("default", "people", "/path/to/default.json");
}

How it works

  • At build time, the MongoDB binaries (mongod, mongoimport and mongoexport) are copied to your project output directory,
  • At runtime, the library chooses the right binaries for your operating system,
  • MongoRunner.Run always starts a new mongod process with a random available port,
  • The resulting connection string will depend on your options (UseSingleNodeReplicaSet and AdditionalArguments),
  • By default, a unique temporary data directory is used.

Tips

Try not to call MongoRunner.Run in parallel, as this will create many mongod processes and make your operating system slower. Instead, try to use a single instance and reuse it - create as many databases as you need, one per test for example.

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.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 was computed. 
.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 (4)

Showing the top 4 NuGet packages that depend on EphemeralMongo.Core:

Package Downloads
EphemeralMongo6

.NET native wrapper for MongoDB 6.0.9 built for .NET Standard 2.0.

EphemeralMongo5

.NET native wrapper for MongoDB 5.0.20 built for .NET Standard 2.0.

EphemeralMongo7

.NET native wrapper for MongoDB 7.0.0 built for .NET Standard 2.0.

EphemeralMongo4

.NET native wrapper for MongoDB 4.4.24 built for .NET Standard 2.0.

GitHub repositories (8)

Showing the top 5 popular GitHub repositories that depend on EphemeralMongo.Core:

Repository Stars
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
abpframework/abp-samples
Sample solutions built with the ABP Framework
Avanade/Liquid-Application-Framework
Liquid Application Framework documentation, useful links and sample project
EasyAbp/EShop
An abp application module group that provides basic e-shop service.
serilog-contrib/serilog-ui
Simple Serilog log viewer UI for several sinks.
Version Downloads Last updated
1.1.3 646,128 8/30/2023
1.1.2 69,698 7/2/2023
1.1.0 120,902 3/9/2023
1.0.0 100,213 2/22/2023
0.1.3 149,543 10/11/2022
0.1.2 10,144 8/5/2022
0.1.1 2,374 8/2/2022
0.1.0 3,027 7/31/2022