MongoQ.AspNetCore
0.1.33-alpha
See the version list below for details.
dotnet add package MongoQ.AspNetCore --version 0.1.33-alpha
NuGet\Install-Package MongoQ.AspNetCore -Version 0.1.33-alpha
<PackageReference Include="MongoQ.AspNetCore" Version="0.1.33-alpha" />
paket add MongoQ.AspNetCore --version 0.1.33-alpha
#r "nuget: MongoQ.AspNetCore, 0.1.33-alpha"
// Install MongoQ.AspNetCore as a Cake Addin #addin nuget:?package=MongoQ.AspNetCore&version=0.1.33-alpha&prerelease // Install MongoQ.AspNetCore as a Cake Tool #tool nuget:?package=MongoQ.AspNetCore&version=0.1.33-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 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);
});
});
Customize default database settings:
app.MongoQConfigureDbSettings(options =>
{
options.ReadPreference = ReadPreference.Nearest;
options.WriteConcern = WriteConcern.WMajority;
options.ReadConcern = ReadConcern.Majority;
});
Product | Versions 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. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- MongoQ (>= 0.1.33-alpha)
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 | |
---|---|---|---|
0.1.35-alpha | 170 | 5/10/2022 | |
0.1.34-alpha | 180 | 5/10/2022 | |
0.1.33 | 492 | 3/13/2022 | |
0.1.33-alpha | 164 | 3/13/2022 | |
0.1.32 | 452 | 2/12/2022 | |
0.1.32-alpha | 152 | 2/12/2022 | |
0.1.31-alpha | 171 | 2/12/2022 | |
0.1.29-alpha | 173 | 1/30/2022 | |
0.1.28-alpha | 177 | 1/29/2022 | |
0.1.26-alpha | 188 | 12/7/2021 | |
0.1.25-alpha | 259 | 10/12/2021 | |
0.1.24-alpha | 246 | 8/20/2021 | |
0.1.23-alpha | 215 | 8/19/2021 | |
0.1.14 | 301 | 8/16/2021 | |
0.1.1 | 313 | 8/16/2021 | |
0.0.1 | 298 | 8/14/2021 |
Changed build to run .NET Standard 2.0 so it has greater compatibility.