MinimalMongo 0.1.37-alpha

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

// Install MinimalMongo as a Cake Tool
#tool nuget:?package=MinimalMongo&version=0.1.37-alpha&prerelease                

MinimalMongo

Quickly add the MongoDB C# Driver to a dotnet project with some helpful additions to get started faster.

Usage:

Creating a repository is very easy with MinimalMongo. MinimalMongo will setup your collection for you in a standard, repeatable way so you can focus on your repository code.

using MinimalMongo;
    
public class MyRepo : MinimalMongoRepo<MyEntity>
{
    public MyRepo() : base("collectionName") { }

    public MyEntity FindOne(ObjectId id)
    {
        return _collection
            .Find(e => e.Id == id)
            .FirstOrDefault();
    }
}

Getting started

Installation

Add the Nuget Package.

For ASP.NET:

Install-Package MinimalMongo.AspNetCore

Generic C#:

Install-Package MinimalMongo

First, Configure your mongo database

See below, configuration is different per-environment to conform to conventions of your framework.

Create a Repo

Inherit your repository from MinimalMongoRepo<T> where T is the class of your entity.

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System.Threading.Tasks;
    
public class MyEntity
{
    [BsonId]
    public ObjectId Id { get; set; }
}
public class MyRepo : MinimalMongo.MinimalMongoRepo<MyEntity>
{
    public MyRepo() : base("collectionName") { }

    public async Task<MyEntity> FindOne(ObjectId id)
    {
        return await _collection
            .Find(e => e.Id == id)
            .FirstOrDefaultAsync();
    }
}

Configuration

AspnetCore Configuration

In your Startup.cs setup mongo in the Startup.Configure method using the IApplicationBuilder app parameter:

Set Database Name:

app.MinimalMongoSetDbName("MyDatabase");

Set Connection string:

app.MinimalMongoSetConnString(config.GetConnectionString("myConnString"));

Customize default database settings:

app.MongoQConfigureDbSettings(options =>
{
    options.ReadPreference = ReadPreference.Nearest;
    options.WriteConcern = WriteConcern.WMajority;
    options.ReadConcern = ReadConcern.Majority;
});

Optionally, customize the cluster:

app.MinimalMongoConfigureCluster(options =>
{
    // configure the connection pool
    options.ConfigureConnectionPool(
        (c) => new ConnectionPoolSettings(
            c.MaintenanceInterval,
            c.MaxConnections,
            c.MinConnections,
            c.WaitQueueSize,
            c.WaitQueueTimeout
        ));

    // subscribe to command failed events
    options.Subscribe<MongoDB.Driver.Core.Events.CommandFailedEvent>(e =>
    {
        System.Diagnostics.Debug.WriteLine($"Mongo Event:{e.GetType().Name}");
        System.Diagnostics.Debug.WriteLine($"CMD COMMAND FAILED:{e.CommandName}");
        System.Diagnostics.Debug.WriteLine($"CMD Exception:{e.Failure}");
    });
    // see generated commands in output
    options.Subscribe<MongoDB.Driver.Core.Events.CommandStartedEvent>(e =>
    {
        System.Diagnostics.Debug.WriteLine($"Mongo Event:{e.GetType().Name}");
        System.Diagnostics.Debug.WriteLine("CMD Start:" + e.Command?.ToJson());
        System.Diagnostics.Debug.WriteLine("CMD Name:" + e.CommandName);
    });
});
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 (1)

Showing the top 1 NuGet packages that depend on MinimalMongo:

Package Downloads
MinimalMongo.AspNetCore

Quickly add the MongoDB C# Driver to an ASP.NET project with some helpful additions to get started quicker.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.37 312 4/2/2023
0.1.37-alpha 184 4/2/2023
0.1.36 330 8/13/2022
0.1.36-alpha 195 8/13/2022

Changed build to run .NET Standard 2.0 so it has greater compatibility.