rhighs.MongoDB.Embedded.CrossPlatform 1.0.0

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

// Install rhighs.MongoDB.Embedded.CrossPlatform as a Cake Tool
#tool nuget:?package=rhighs.MongoDB.Embedded.CrossPlatform&version=1.0.0                

MongoDB.Embedded.CrossPlatform

A .NET package that provides an easy way to integrate and manage a MongoDB server within your .NET applications. It abstracts the complexities of setting up and running a MongoDB instance, allowing the embedded MongoDB executable to be packaged directly within your application's DLLs. This package supports Windows, Linux, and OSX platforms, ensuring a seamless MongoDB experience across different environments. Such a package is particularly useful for testing purposes, in particular, intergration testing.

Getting Started

1. Installation

To install EmbeddedMongoDbServer, you can use NuGet package manager. The following command will install the package into your project:

Install-Package MongoDB.Embedded.CrossPlatform
2. Basic Usage

Here is a simple example of how to use EmbeddedMongoDbServer to start a MongoDB instance and perform basic operations:

using MongoDB.Embedded;
using MongoDB.Driver;

// Initialize the embedded MongoDB server
using (var embeddedServer = new EmbeddedMongoDbServer())
{
    // Get the MongoClient
    var client = embeddedServer.Client;

    // Use the client as you would normally...
    var database = client.GetDatabase("yourDatabase");
    var collection = database.GetCollection<YourDataType>("yourCollection");
    // Perform operations (CRUD) on the collection
}

The EmbeddedMongoDbServer instance takes care of setting up and tearing down the MongoDB server automatically.

3. Advanced Configuration

EmbeddedMongoDbServer offers several configuration options to tailor the MongoDB instance to your needs, such as setting custom database paths, enabling logging, and more.

using MongoDB.Embedded;

var customSettings = new EmbeddedMongoDbServerSettings
{
    LogPath = "path/to/your/logs",
    DatabasePath = "path/to/your/database",
    LogEnabled = true
};

using (var embeddedServer = new EmbeddedMongoDbServer(customSettings))
{
    IMongoClient client = embeddedServer.Client;
    // Your code to interact with the mongodb client, already setup and connected!
}

Testing with EmbeddedMongoDbServer

EmbeddedMongoDbServer is ideal for integration testing, allowing you to run tests against a real MongoDB instance with minimal setup. Here's an example of how you might write tests:

using MongoDB.Driver;
using MongoDB.Embedded;
using Xunit;

public class MongoDBTests
{
    [Fact]
    public void BasicStartupTest()
    {
        using (var embedded = new EmbeddedMongoDbServer())
        {
            var client = embedded.Client;
            // Perform tests using the client...
        }
    }

    [Fact]
    public async Task ReadWriteTest()
    {
        using (var embedded = new EmbeddedMongoDbServer())
        {
            var client = embedded.Client;
            var db = client.GetDatabase("test");
            var collection = db.GetCollection<TestClass>("col");

            await collection.InsertOneAsync(new TestClass { Id = 12345, TestValue = "Hello world." });
            var retrieved = await collection.Find(x => x.Id == 12345).SingleOrDefaultAsync();

            Assert.NotNull(retrieved);
            Assert.Equal("Hello world.", retrieved.TestValue);
        }
    }
}

Support and Contributions

For support, questions, or contributions, please consider the following:

  • Issues: If you encounter any issues or bugs, please report them in the issues section of the GitHub repository.
  • Contributions: Contributions are welcome! If you'd like to improve or add new features, feel free to fork the repository and submit a pull request.

MIT License.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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.2.5 226 2/2/2024 1.2.5 is deprecated because it has critical bugs.
1.2.4 127 2/1/2024
1.2.3 144 2/1/2024
1.2.2 155 1/29/2024
1.2.1 159 1/26/2024
1.2.0 134 1/26/2024
1.1.2 272 1/24/2024
1.1.0 278 1/24/2024
1.0.0 292 1/23/2024