MongoQ 0.1.35-alpha

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

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

MongoQ

The Q stands for quick

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

Usage:

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

using MongoQ;
    
public class MyRepo : MongoQRepo<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 MongoQ.AspNetCore

Generic C#:

Install-Package MongoQ

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 MongoQRepo<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 : MongoQ.MongoQRepo<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.MongoQSetDbName("MyDatabase");

Set Connection string:

app.MongoQSetConnString(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.MongoQConfigureCluster(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 MongoQ:

Package Downloads
MongoQ.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.35-alpha 238 5/10/2022
0.1.34-alpha 255 5/10/2022
0.1.33 797 3/13/2022 0.1.33 is deprecated because it is no longer maintained.
0.1.33-alpha 257 3/13/2022
0.1.32 753 2/12/2022
0.1.32-alpha 222 2/12/2022
0.1.31-alpha 244 2/12/2022
0.1.29-alpha 254 1/30/2022
0.1.28-alpha 264 1/29/2022
0.1.26-alpha 258 12/7/2021
0.1.25-alpha 343 10/12/2021
0.1.24-alpha 308 8/20/2021
0.1.23-alpha 307 8/19/2021
0.1.13 371 8/15/2021
0.1.1 460 8/16/2021
0.0.1 438 8/14/2021

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