XYS.Mongo
3.0.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
dotnet add package XYS.Mongo --version 3.0.0
NuGet\Install-Package XYS.Mongo -Version 3.0.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="XYS.Mongo" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XYS.Mongo" Version="3.0.0" />
<PackageReference Include="XYS.Mongo" />
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 XYS.Mongo --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XYS.Mongo, 3.0.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 XYS.Mongo@3.0.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=XYS.Mongo&version=3.0.0
#tool nuget:?package=XYS.Mongo&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XYS.Mongo
基于 MongoDB.Driver 的通用数据访问库:泛型仓储 + 上下文工厂,异步优先。
特性
MongoContext入口:按连接串缓存IMongoClient(官方推荐的单例复用),分发集合/仓储/索引管理器;FromConfig接xys.config.json。MongoRepository<T>泛型仓储:CRUD 同步 + 异步(异步带CancellationToken),消费者可继承扩展。MongoRepositoryManager<T>索引管理:EnsureIndex/DropIndex/IndexExists 等,同步 + 异步。- 驱动异常原样冒泡(不吞不包装);仅配置错误抛
MongoConfigurationException。 - 多目标:net8.0 / net462 / netcoreapp3.1 / netstandard2.0 / netstandard2.1。
快速开始
using XYS.Mongo;
using XYS.Mongo.Repository;
// 1. 从 xys.config.json 的 connectionStrings 节点构造
var ctx = MongoContext.FromConfig("sms");
// 2. 取仓储
var repo = ctx.Repository<SmsSendME>();
// 3. 异步 CRUD
await repo.AddAsync(new SmsSendME { /* ... */ });
var list = await repo.FindMultipleAsync(repo.FilterBuiler.Eq(x => x.Status, 0));
long n = await repo.CountAsync();
继承用法(保留)
public class SmsSendReqRepository : MongoRepository<SmsSendME>
{
// 经 MongoContext 获取实例,或沿用既有静态单例
}
实体与集合名
- 实体实现
IEntity<TKey>或继承BaseME(字符串 ObjectId 主键)。 - 集合名解析顺序:
[CollectionName("...")]特性 → BaseME 继承链顶层类名 → 类型名。
配置(xys.config.json)
"connectionStrings": {
"sms": {
"connectionString": "mongodb://user:pwd@host:27017/smsdb"
}
}
连接串含库名即可;库名缺失时用 MongoOptions.DatabaseName 覆盖。仓库内 xys.config.json 不写明文凭据。
索引管理
var mgr = ctx.Manager<SmsSendME>();
mgr.EnsureIndex("Status");
bool ok = mgr.IndexExists("Status");
3.0.0 变更(不兼容点)
- 新增
MongoContext工厂层,按连接串缓存MongoClient(修复旧版每仓储实例新建 client 的反模式)。 - 修复必崩 Bug:
Count()/Count(predicate)自递归爆栈、DeleteAsync(TKey)假异步、DeleteAllAsync()为async void。 Delete*Async返回类型void → Task。IRepository<T,TKey>去掉IQueryable<T>基接口,改为AsQueryable()返回IMongoQueryable<T>。- 删除面向 MMAPv1 的
MongoRepositoryManager统计/校验(GetStats/Validate/ReIndex/GetTotalDataSize/GetTotalStorageSize/IsCapped)——在 WiredTiger 上本就抛异常。 - 旧
MongoRepository构造函数标[Obsolete](仍可用,内部改走缓存 client)。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. 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.
-
.NETCoreApp 3.1
- MongoDB.Driver (>= 2.30.0)
- XYS.Utils.Sys (>= 2.5.0)
-
.NETFramework 4.6.2
- MongoDB.Driver (>= 2.30.0)
- XYS.Utils.Sys (>= 2.5.0)
-
.NETStandard 2.0
- MongoDB.Driver (>= 2.30.0)
- XYS.Utils.Sys (>= 2.5.0)
-
.NETStandard 2.1
- MongoDB.Driver (>= 2.30.0)
- XYS.Utils.Sys (>= 2.5.0)
-
net8.0
- MongoDB.Driver (>= 2.30.0)
- XYS.Utils.Sys (>= 2.5.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on XYS.Mongo:
| Package | Downloads |
|---|---|
|
XYS.Lab.Mongo
Package Description |
|
|
XYS.His.Hos.Mongo
Package Description |
|
|
XYS.Message.Mongo
Package Description |
|
|
XYS.Emr.Mongo
Description |
GitHub repositories
This package is not used by any popular GitHub repositories.