VOOZH about

URL: https://www.nuget.org/packages/HMENetCore.MongoDB/

⇱ NuGet Gallery | HMENetCore.MongoDB 10.0.9




HMENetCore.MongoDB 10.0.9

dotnet add package HMENetCore.MongoDB --version 10.0.9
 
 
NuGet\Install-Package HMENetCore.MongoDB -Version 10.0.9
 
 
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="HMENetCore.MongoDB" Version="10.0.9" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HMENetCore.MongoDB" Version="10.0.9" />
 
Directory.Packages.props
<PackageReference Include="HMENetCore.MongoDB" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HMENetCore.MongoDB --version 10.0.9
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HMENetCore.MongoDB, 10.0.9"
 
 
#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.
#:package HMENetCore.MongoDB@10.0.9
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HMENetCore.MongoDB&version=10.0.9
 
Install as a Cake Addin
#tool nuget:?package=HMENetCore.MongoDB&version=10.0.9
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

HMENetCore.MongoDB

简介

HMENetCore.MongoDB 是基于官方MongoDB.Driver的增强封装库,专为.NET Core应用提供更便捷的MongoDB集成方案。支持MongoDB 4.0+版本,提供符合领域驱动设计(DDD)的仓储模式实现。

核心优势

🚀 性能优化

  • 智能连接池管理(默认100-500连接)
  • 批量操作自动优化
  • 异步全链路支持

🔐 企业级安全

  • TLS/SSL加密支持
  • 完善的错误重试机制
  • 事务ACID保证

🧩 开箱即用

  • 自动集合命名映射
  • 内置常用CRUD操作
  • 支持LINQ表达式查询

功能特性

  • 清洁架构:Context → Repository → Service 清晰分层
  • 全异步支持:所有方法均提供Async版本
  • 事务支持:跨操作事务一致性保证
  • 灵活配置:支持多节点集群、SSL连接、连接池调优
  • 智能映射:自动处理集合命名与类型映射

运行环境

  • 跨平台支持: Supports .NET Standard 2.1, .NET 8, and .NET 10.

安装

dotnet add package HMENetCore.MongoDB

配置数据库连接

添加配置到 appsettings.json

{
 "MongoConfig": {
 "ConnectionStrings": ["server1:27017", "server2:27017"],
 "DbName": "your_db",
 "UserName": "user",
 "Password": "pwd",
 "UseSsl": true,
 "MaxPoolSize": 500
 }
}

服务注册

builder.Services.Configure<MongoConfig>(builder.Configuration.GetSection("MongoConfig"));
builder.Services.AddMongoDBSetup(builder.Configuration.Get<MongoConfig>()!);

使用案例:

1.定义实体

[Table("users")]
public class User 
{
 [BsonId]
 public string Id { get; set; }
 public string Name { get; set; }
 public DateTime CreateTime { get; set; }
}

2.创建仓储

public class UserRepository : BaseMongoRepository<User>
{
 public UserRepository(IMongoContext context) : base(context) 
 {
 }
 
 // 自定义查询方法
 public async Task<List<User>> GetActiveUsersAsync()
 {
 var collection = GetCollection();
 return await collection.Find(u => u.CreateTime > DateTime.UtcNow.AddDays(-30))
 .ToListAsync();
 }
}

3.业务服务

public class UserService : BaseMongoService<User>
{
 public UserService(IMongoCRUD<User> repository) : base(repository) 
 {
 }

 public async Task UpdateUserWithTransactionAsync(string userId, Action<User> update)
 {
 using var session = await StartSessionAsync();
 session.StartTransaction();
 
 try {
 var user = await FindByIdAsync(userId);
 update(user);
 await ReplaceOneAsync(userId, user);
 
 await session.CommitTransactionAsync();
 }
 catch {
 await session.AbortTransactionAsync();
 throw;
 }
 }
}

核心组件

1. IMongoContext

提供对 MongoContext 的基本操作接口。

2. BaseMongoRepository

仓储层基类,实现了 IMongoCRUD 接口,提供对特定实体的 CRUD 操作。

3. BaseMongoService

服务层基类,封装了仓储层的操作,可以在此基础上添加业务逻辑。

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 netstandard2.1 is compatible. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos 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
10.0.9 100 5/21/2026
10.0.8 99 5/18/2026
10.0.7 159 3/17/2026
10.0.5 127 2/24/2026
10.0.3 140 1/14/2026
10.0.1 505 12/10/2025
10.0.0 240 11/28/2025
6.1.10 100 5/21/2026
6.1.9 98 5/18/2026
6.1.8 131 3/17/2026
6.1.6 123 2/24/2026
6.1.5 149 1/14/2026
6.1.2 493 12/10/2025
6.1.0 246 11/24/2025
6.0.52 263 10/20/2025
6.0.51 235 9/23/2025
6.0.50 392 9/18/2025
Loading failed