laget.Db.Mongo
1.3.36
Prefix Reserved
dotnet add package laget.Db.Mongo --version 1.3.36
NuGet\Install-Package laget.Db.Mongo -Version 1.3.36
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="laget.Db.Mongo" Version="1.3.36" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add laget.Db.Mongo --version 1.3.36
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: laget.Db.Mongo, 1.3.36"
#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 laget.Db.Mongo as a Cake Addin
#addin nuget:?package=laget.Db.Mongo&version=1.3.36
// Install laget.Db.Mongo as a Cake Tool
#tool nuget:?package=laget.Db.Mongo&version=1.3.36
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
laget.Db.Mongo
A repository pattern implementation for MongoDB, a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.
Configuration
This example is shown using Autofac since this is the go-to IoC for us.
public class DatabaseModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new MongoDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("MongoConnectionString"))).As<IMongoDefaultProvider>().SingleInstance();
}
}
public class DatabaseModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new MongoDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("MongoConnectionString"), new MongoDatabaseSettings
{
ReadConcern = ReadConcern.Default,
ReadPreference = ReadPreference.SecondaryPreferred,
WriteConcern = WriteConcern.W3
})).As<IMongoDefaultProvider>().SingleInstance();
}
}
public class DatabaseModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new MongoDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("MongoConnectionString"), new MemoryCacheOptions
{
CompactionPercentage = 0.25,
ExpirationScanFrequency = TimeSpan.FromMinutes(5),
SizeLimit = 1024
})).As<IMongoDefaultProvider>().SingleInstance();
}
}
public class DatabaseModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new MongoDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("MongoConnectionString"), new MongoDatabaseSettings
{
ReadConcern = ReadConcern.Default,
ReadPreference = ReadPreference.SecondaryPreferred,
WriteConcern = WriteConcern.W3
}, new MemoryCacheOptions
{
CompactionPercentage = 0.25,
ExpirationScanFrequency = TimeSpan.FromMinutes(5),
SizeLimit = 1024
})).As<IMongoDefaultProvider>().SingleInstance();
}
}
Usage
Built-in methods
public interface IRepository<TEntity> where TEntity : Entity
{
IEnumerable<TEntity> Find(FilterDefinition<TEntity> filter);
Task<IEnumerable<TEntity>> FindAsync(FilterDefinition<TEntity> filter);
TEntity Get(string id);
Task<TEntity> GetAsync(string id);
TEntity Get(FilterDefinition<TEntity> filter);
Task<TEntity> GetAsync(FilterDefinition<TEntity> filter);
void Insert(IEnumerable<TEntity> entities);
Task InsertAsync(IEnumerable<TEntity> entities);
void Insert(TEntity entity);
Task InsertAsync(TEntity entity);
void Update(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update, UpdateOptions options);
Task UpdateAsync(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update, UpdateOptions options);
void Upsert(IEnumerable<TEntity> entities);
Task UpsertAsync(IEnumerable<TEntity> entities);
void Upsert(TEntity entity);
Task UpsertAsync(TEntity entity);
void Upsert(FilterDefinition<TEntity> filter, TEntity entity);
Task UpsertAsync(FilterDefinition<TEntity> filter, TEntity entity);
void Delete(IEnumerable<TEntity> entities);
Task DeleteAsync(IEnumerable<TEntity> entities);
void Delete(TEntity entity);
Task DeleteAsync(TEntity entity);
void Delete(FilterDefinition<TEntity> filter);
Task DeleteAsync(FilterDefinition<TEntity> filter);
}
Generic
public interface IUserRepository : IRepository<Models.User>
{
}
public class UserRepository : Repository<Models.User>, IUserRepository
{
public UserRepository(string connectionString)
: base(connectionString)
{
}
}
Caching
public interface IUserRepository : IRepository<Models.User>
{
}
public class UserRepository : Repository<Models.User>, IUserRepository
{
public UserRepository(string connectionString)
: base(connectionString)
{
}
public override Models.User Get(string id)
{
var cacheKey = "_Id_" + id;
var item = CacheGet<Models.User>(cacheKey);
if (item != null)
return item;
var result = Get(id);
CacheAdd(cacheKey, result);
return result;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. |
.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.
-
.NETStandard 2.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- MongoDB.Driver (>= 2.24.0)
- System.ComponentModel.Annotations (>= 5.0.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- MongoDB.Driver (>= 2.24.0)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- MongoDB.Driver (>= 2.24.0)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- MongoDB.Driver (>= 2.24.0)
- System.ComponentModel.Annotations (>= 5.0.0)
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.3.36 | 397 | 3/4/2024 | |
1.3.35 | 316 | 1/20/2024 | |
1.3.33 | 272 | 12/21/2023 | |
1.2.32 | 268 | 11/22/2023 | |
1.2.31 | 648 | 7/3/2023 | |
1.2.29 | 234 | 3/10/2023 | |
1.1.27 | 241 | 3/6/2023 | |
1.1.25 | 298 | 2/6/2023 | |
1.1.22 | 299 | 12/5/2022 | |
1.1.21 | 375 | 10/24/2022 | |
1.1.17 | 404 | 8/22/2022 | |
1.1.16 | 449 | 7/4/2022 | |
1.1.15 | 405 | 6/7/2022 | |
1.1.14 | 440 | 4/4/2022 | |
1.1.13 | 389 | 4/4/2022 | |
1.1.12 | 419 | 3/10/2022 | |
1.1.11 | 428 | 2/7/2022 | |
1.1.10 | 283 | 12/21/2021 | |
1.1.9 | 287 | 12/6/2021 | |
1.1.8 | 261 | 11/28/2021 | |
1.1.7 | 347 | 11/1/2021 | |
1.1.6 | 391 | 11/1/2021 | |
1.1.5 | 369 | 10/4/2021 | |
1.1.4 | 416 | 8/16/2021 | |
1.1.3 | 363 | 8/9/2021 | |
1.1.2 | 463 | 6/7/2021 | |
1.1.1 | 492 | 5/21/2021 | |
1.0.25 | 409 | 5/5/2021 | |
1.0.24 | 401 | 5/3/2021 | |
1.0.23 | 447 | 4/6/2021 | |
1.0.22 | 428 | 3/5/2021 | |
1.0.21 | 410 | 3/5/2021 | |
1.0.20 | 420 | 2/11/2021 | |
1.0.19 | 364 | 2/1/2021 | |
1.0.18 | 609 | 1/8/2021 | |
1.0.17 | 457 | 1/1/2021 | |
1.0.16 | 425 | 12/23/2020 | |
1.0.15 | 431 | 12/22/2020 | |
1.0.14 | 551 | 12/22/2020 | |
1.0.13 | 646 | 12/16/2020 | |
1.0.12 | 508 | 12/9/2020 | |
1.0.11 | 401 | 12/9/2020 | |
1.0.10 | 414 | 12/9/2020 | |
1.0.9 | 479 | 12/8/2020 | |
1.0.8 | 485 | 12/8/2020 | |
1.0.7 | 482 | 12/8/2020 | |
1.0.2 | 483 | 12/8/2020 |