Shipeng.Data.MongoDB
4.1.0
See the version list below for details.
dotnet add package Shipeng.Data.MongoDB --version 4.1.0
NuGet\Install-Package Shipeng.Data.MongoDB -Version 4.1.0
<PackageReference Include="Shipeng.Data.MongoDB" Version="4.1.0" />
<PackageVersion Include="Shipeng.Data.MongoDB" Version="4.1.0" />
<PackageReference Include="Shipeng.Data.MongoDB" />
paket add Shipeng.Data.MongoDB --version 4.1.0
#r "nuget: Shipeng.Data.MongoDB, 4.1.0"
#:package Shipeng.Data.MongoDB@4.1.0
#addin nuget:?package=Shipeng.Data.MongoDB&version=4.1.0
#tool nuget:?package=Shipeng.Data.MongoDB&version=4.1.0
Shipeng.Data.MongoDB
Shipeng.Data.MongoDB 提供 MongoDB 数据访问基础能力,包括上下文、客户端封装、Host/Options 配置、Repository 辅助和依赖注入扩展。它适合日志、轨迹、事件、读模型、弱事务文档数据等 MongoDB 场景。
安装
dotnet add package Shipeng.Data.MongoDB
适用场景
- 业务需要直接使用 MongoDB.Driver,但希望统一连接、数据库、集合访问方式。
- 读模型、审计日志、轨迹数据、事件数据使用 MongoDB 保存。
- 多项目需要复用 MongoDB 上下文注册、连接字符串配置和常用辅助方法。
主要类型
MongoDBContextOptions:MongoDB 连接配置模型,通常承载连接字符串、数据库名等选项。MongoDBContext:MongoDB 数据访问上下文,集中管理客户端、数据库和集合访问。MongoDBClient:MongoDB 客户端封装入口。MongoDBContextServiceCollectionExtensions:把 MongoDB 上下文注册到 DI 的扩展方法。MongoDBHelper:常用 MongoDB 操作辅助方法。MongoDBHost:MongoDB Host/运行环境封装。TraceDbMongoDBContext:面向轨迹/追踪库的上下文类型。
基本用法
using Shipeng.Foundation.Data.MongoDB;
var builder = WebApplication.CreateBuilder(args);
// 推荐从 appsettings.json 读取 MongoDB 配置,再通过包内扩展方法注册。
// builder.Services.AddMongoDBContext(builder.Configuration);
var app = builder.Build();
app.Run();
使用建议
- MongoDB 连接字符串、数据库名和集合命名应放在配置文件或密钥系统中,不要硬编码。
- 高频查询字段必须建立索引;索引声明和启动确保能力可配合
Shipeng.DatabaseIndex使用。 - 文档模型不要无限制膨胀,日志和事件类集合应设计保留周期和归档策略。
- 事务需求强的业务仍应优先使用关系数据库或显式 MongoDB Transaction。
引用关系
本包引用 Shipeng.Foundation、MongoDB.Driver、MongoDB.Bson 和 Microsoft.Extensions 配置/DI 相关包。只需要 SQL ORM 时请引用 Shipeng.Data.SqlSugar 或 Shipeng.EntityFrameworkCore。
API Reference / API 索引
完整公开类型、方法、属性签名请查看 API_REFERENCE.md。该文件从源码 public 声明生成,用于补充 README 中的场景说明和示例。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- MongoDB.Bson (>= 3.9.0)
- MongoDB.Driver (>= 3.9.0)
- Shipeng.Foundation (>= 4.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Shipeng.Data.MongoDB:
| Package | Downloads |
|---|---|
|
Shipeng.Data.Hybrid
Hybrid MongoDB and SqlSugar paging helper package for read-model scenarios that query MongoDB first and fall back to SQL data when needed. |
GitHub repositories
This package is not used by any popular GitHub repositories.
4.1.0: Split the original monolithic foundation library into focused Shipeng.* NuGet packages. Consumers can reference authentication, MongoDB, SqlSugar, EF Core, database index, third-party integration, logging, mapping, payment, and hybrid paging capabilities on demand.