Shipeng.Data.MongoDB 4.1.0

There is a newer version of this package available.
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
                    
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="Shipeng.Data.MongoDB" Version="4.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shipeng.Data.MongoDB" Version="4.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Shipeng.Data.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 Shipeng.Data.MongoDB --version 4.1.0
                    
#r "nuget: Shipeng.Data.MongoDB, 4.1.0"
                    
#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 Shipeng.Data.MongoDB@4.1.0
                    
#: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=Shipeng.Data.MongoDB&version=4.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Shipeng.Data.MongoDB&version=4.1.0
                    
Install as a Cake Tool

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.FoundationMongoDB.DriverMongoDB.Bson 和 Microsoft.Extensions 配置/DI 相关包。只需要 SQL ORM 时请引用 Shipeng.Data.SqlSugarShipeng.EntityFrameworkCore

API Reference / API 索引

完整公开类型、方法、属性签名请查看 API_REFERENCE.md。该文件从源码 public 声明生成,用于补充 README 中的场景说明和示例。

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
4.1.1 129 6/30/2026
4.1.0 124 6/30/2026

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.