Shipeng.Data.MongoDB
4.1.1
dotnet add package Shipeng.Data.MongoDB --version 4.1.1
NuGet\Install-Package Shipeng.Data.MongoDB -Version 4.1.1
<PackageReference Include="Shipeng.Data.MongoDB" Version="4.1.1" />
<PackageVersion Include="Shipeng.Data.MongoDB" Version="4.1.1" />
<PackageReference Include="Shipeng.Data.MongoDB" />
paket add Shipeng.Data.MongoDB --version 4.1.1
#r "nuget: Shipeng.Data.MongoDB, 4.1.1"
#:package Shipeng.Data.MongoDB@4.1.1
#addin nuget:?package=Shipeng.Data.MongoDB&version=4.1.1
#tool nuget:?package=Shipeng.Data.MongoDB&version=4.1.1
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 索引
nuget.org 当前只会直接渲染包的 README 和 Release Notes,不会把包内 docs/API_REFERENCE.md 自动显示成一个独立页面标签。完整公开 API 索引已经随 NuGet 包打入 docs/API_REFERENCE.md,也可以在源码仓库中查看。
如果你正在 NuGet 页面阅读本文,请优先看本 README 的“主要类型”和示例;下载包后可在包内容中打开 docs/API_REFERENCE.md 查看完整公开类型、方法、属性和构造函数签名。
| 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.1)
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.1 / 2026-06-30
English:
- Split the original monolithic foundation library into focused Shipeng.* NuGet packages so applications can reference only the capabilities they actually need.
- Added Shipeng.DatabaseMaintenance for SQL Server and MongoDB database maintenance. It supports non-destructive cleanup preview, SqlSugar entity scanning, MongoDB collection scanning from configuration or source declarations, keep lists, ignored prefixes, empty-scan protection, missing table preview, controlled SqlSugar CodeFirst table creation, SQL Server schema difference preview, safe missing-column creation, safe changed-column synchronization, explicit execution switches, and confirmation-code protected destructive/schema-changing execution.
- Improved Shipeng.Payment with a unified payment abstraction for WeChat, Alipay, UnionPay, Cloud QuickPass, bank gateways, and profit-sharing scenarios. WeChat Pay V3 remains the concrete built-in implementation; other channels expose stable provider contracts and explicit placeholders so applications can add real vendor SDK implementations without changing business code.
- Centralized common NuGet metadata in Directory.Build.props: target framework, version, authors, repository, license, README, XML documentation, warning policy, and release notes.
- Every package includes README.md, XML IntelliSense documentation, and docs/API_REFERENCE.md inside the generated nupkg.
- Updated README files to explain that nuget.org renders README and Release Notes directly but does not expose packaged docs/API_REFERENCE.md as a separate page tab.
- Release build validation: all projects build and pack successfully for net10.0 with 0 warnings and 0 errors.
中文:
- 将早期单体基础库拆分为职责更清晰的 Shipeng.* NuGet 包,业务项目可以按需引用认证、MongoDB、SqlSugar、EF Core、数据库索引、数据库维护、第三方集成、日志、映射、支付和混合分页能力。
- 新增 Shipeng.DatabaseMaintenance,用于 SQL Server 和 MongoDB 数据库维护。支持冗余表/集合预览清理、SqlSugar 实体扫描、MongoDB 配置集合扫描、源码集合声明扫描、保留名单、忽略前缀、空扫描保护、缺失表预览、受控 CodeFirst 自动建表、SQL Server 结构差异预览、缺失字段补齐、安全字段同步、显式执行开关和确认码保护。
- 增强 Shipeng.Payment,新增统一支付抽象,覆盖微信、支付宝、银联、云闪付、银行网关和分账场景。微信支付 V3 是当前内置可用实现;其他通道提供稳定 Provider 契约和明确占位实现,方便业务项目接入真实厂商 SDK。
- 将公共 NuGet 元数据统一集中到 Directory.Build.props,避免各项目 PropertyGroup 重复和不一致。
- 每个包都打入 README.md、XML IntelliSense 文档和 docs/API_REFERENCE.md。
- 所有 README 都补充说明:nuget.org 会直接显示 README 和 Release Notes,但不会把包内 docs/API_REFERENCE.md 自动显示为独立标签页。
- 已验证 Release 构建和打包,目标框架 net10.0,0 警告,0 错误。