diff --git a/src/BPA.Component.DbClient/BPA.Component.DbClient/RepositoryModel/BaseDbClient.cs b/src/BPA.Component.DbClient/BPA.Component.DbClient/BaseDbClient.cs similarity index 97% rename from src/BPA.Component.DbClient/BPA.Component.DbClient/RepositoryModel/BaseDbClient.cs rename to src/BPA.Component.DbClient/BPA.Component.DbClient/BaseDbClient.cs index d6b1262..f104fae 100644 --- a/src/BPA.Component.DbClient/BPA.Component.DbClient/RepositoryModel/BaseDbClient.cs +++ b/src/BPA.Component.DbClient/BPA.Component.DbClient/BaseDbClient.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using SqlSugar; -namespace BPA.Component.DbClient.RepositoryModel +namespace BPA.Component.DbClient { /// /// 数据库客户端基类 @@ -19,7 +19,7 @@ namespace BPA.Component.DbClient.RepositoryModel private readonly ILogger _logger; /// - /// 是否打印日志 + /// 是否打印SQL /// private readonly bool _isLogSql; diff --git a/src/BPA.Component.DbClient/BPA.Component.DbClientTester/TestDbClient.cs b/src/BPA.Component.DbClient/BPA.Component.DbClientTester/TestDbClient.cs index 53a79ef..f2605cb 100644 --- a/src/BPA.Component.DbClient/BPA.Component.DbClientTester/TestDbClient.cs +++ b/src/BPA.Component.DbClient/BPA.Component.DbClientTester/TestDbClient.cs @@ -1,4 +1,5 @@ -using BPA.Component.DbClient.RepositoryModel; +using BPA.Component.DbClient; +using BPA.Component.DbClient.RepositoryModel; using Microsoft.Extensions.Logging; using SqlSugar; diff --git a/src/BPA.Component.LogClient/BPA.Component.LogClientTester/Properties/launchSettings.json b/src/BPA.Component.LogClient/BPA.Component.LogClientTester/Properties/launchSettings.json index 92c34c7..66439f9 100644 --- a/src/BPA.Component.LogClient/BPA.Component.LogClientTester/Properties/launchSettings.json +++ b/src/BPA.Component.LogClient/BPA.Component.LogClientTester/Properties/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "Project", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "APOLLO_META_SERVER_URL": "http://192.168.1.222:28080", + "APOLLO_META_SERVER_URL": "http://10.2.1.21:28080", "APOLLO_COMMON_NAMESPACE": "Dev.Common", "APP_NAME": "BPA-DEV" } diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.csproj b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.csproj index e3fa294..9c582e9 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.csproj +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.csproj @@ -18,6 +18,7 @@ + all diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.xml b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.xml deleted file mode 100644 index 0ce96a4..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BPA.Component.MongoClient.xml +++ /dev/null @@ -1,1580 +0,0 @@ - - - - BPA.Component.MongoClient - - - - - MongoDb基础仓储 - - - - - 当前企业(商户)Id - - - - - 当前MongoDB上下文 - - - - - 当前需要操作的文档集 - - - - - MongoDbProvider - - - - - 构造方法 - - - - - - 切换企业Id - - - - - - 检查当前文档集 - - - - - 插入一个 ,等同使用:IMongoCollection.InsertOne - - 文档对象 - 插入配置选项 - - - - 插入多个,等同使用: - IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - - 文档对象 - 插入配置选项 - - - - 插入一个 ,等同使用:IMongoCollection.InsertOneAsync - - 文档对象 - 插入配置选项 - - - - 插入多个,等同使用: - IMongoCollection.InsertManyAsync(IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - - 文档对象 - 插入配置选项 - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOneAsync(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义更新字段和条件,更新单条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新单条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新条符合条件的数据 - - - - - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - 查询添加表达式 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - 查询添加表达式 - - - - - 删除满足条件的第一条数据,等同于 - IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 删除满足条件的第一条数据,等同于 - IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 批量删除满足条件的多条数据,等同于 - IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 批量删除满足条件的多条数据,等同于 - IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 根据条件查询 - - - - - - - - 根据条件查询 - - - - - - - - 可查询 - - - - - - 可查询 根据条件 - - - - - - - 可查询 根据条件 - - - - - - - - 根据条件判断是否存在 - - - - - - - 根据ID获取entity - - - - - - - 根据ID获取entity - - - - - - - 根据ID获取entity - - - 需要返会的字段表达式 - - - - - 根据条件 获取第一条数据 - - 条件 - 返回的新对象选择表达式 - - - - - 根据条件 获取第一条数据 - - 条件 - 返回的新对象选择表达式 - - - - - 根据条件 获取第一条数据 - - - - - - - 根据条件 获取第一条数据 - - - - - - - 根据条件获取集合 - - - - - - - 根据条件获取集合 - - - - - - - 根据条件获取集合 - - - - - - - - 根据条件获取集合 - - - - - - - - 创建过滤条件定义 - - - - - 创建索引条件定义 - - - - - 创建更新条件定义 - - - - - 创建排序条件定义 - - - - - Filter - - - - - Update - - - - - Sort - - - - - BPABsonClassMapSerializationProvider - - - - - - - - 字段名称 驼峰命令 - - - - - Applies a modification to the member map. - - The member map. - - - - BPADefaultConventionPack - - - - - Gets the instance. - - - - - Gets the conventions. - - - - - Initializes a new instance of the class. - - - - - BPASerializationProvider - - - - - - - - JArraySerializer - - - - - Representation - - - - - JArray - - - - - EnumBsonSerializer - - - - - Serialize - - - - - - - - - - - - - - - - Serialize - - - - - - - - EnumBsonSerializer - - - - - - Representation - - - - - EnumBsonSerializer - - - - - Initializes a new instance of the class. - - The representation. - - - - Deserialize - - - - - - - - Serialize - - - - - - - - WithRepresentation - - - - - - - WithRepresentation - - - - - - - 驼峰命名 - - - - - - ToLower - - - - - - - JArraySerializer - - - - - Representation - - - - - JArray - - - - - EnumBsonSerializer - - - - - Serialize - - - - - - - - - - - - - - - - - - - - - - - - JObject - - - - - Representation - - - - - JArray - - - - - EnumBsonSerializer - - - - - Serialize - - - - - - - - - - - - - - - - - - - - - - - - Maps a fully immutable type. This will include anonymous types. - - - - - - - - MongoDB仓储接口 - - - - - 当前企业(商户)Id - - - - - 切换企业Id - - - - - - MongonDbProvider - - - - - 当前MongoDB上下文 - - - - - 当前需要操作的文档集 - - - - - 插入一个 ,等同使用:IMongoCollection.InsertOne - - 文档对象 - 插入配置选项 - - - - 插入多个,等同使用: - IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - - 文档对象 - 插入配置选项 - - - - 插入一个 ,等同使用:IMongoCollection.InsertOneAsync - - 文档对象 - 插入配置选项 - - - - 插入多个,等同使用: - IMongoCollection.InsertManyAsync(IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - - 文档对象 - 插入配置选项 - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOneAsync(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义更新字段和条件,更新单条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新单条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新条符合条件的数据 - - - - - - - - - 自定义更新字段和条件,更新条符合条件的数据 - - - - - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - 查询添加表达式 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象对象 - 查询添加表达式 - - - - - 删除满足条件的第一条数据,等同于 - IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 删除满足条件的第一条数据,等同于 - IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 批量删除满足条件的多条数据,等同于 - IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 批量删除满足条件的多条数据,等同于 - IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - - 删除条件表达式 - - - - 根据条件查询 - - - - - - - - 根据条件查询 - - - - - - - - 可查询 - , 同步时用ToList, 异步时用 ToListAsync - - - - - - 可查询 根据条件 , 同步时用ToList, 异步时用 ToListAsync - - - - - - - 可查询 根据条件 , 同步时用ToList , 异步时用 ToListAsync - - - - - - - - 根据条件判断是否存在 - - - - - - - 根据ID获取entity - - - - - - - 根据ID获取entity - - - - - - - 根据ID获取entity - - - 需要返回的字段表达式 - - - - - 根据条件 获取第一条数据 - - 条件 - 返回的新对象选择表达式 - - - - - 根据条件 获取第一条数据 - - 条件 - 返回的新对象选择表达式 - - - - - 根据条件 获取第一条数据 - - - - - - - 根据条件 获取第一条数据 - - - - - - - 根据条件获取集合 - - - - - - - 根据条件获取集合 - - - - - - - 根据条件获取集合 - - - - - - - - 根据条件获取集合 - - - - - - - - Filter - - - - - Update - - - - - Sort - - - - - 创建过滤条件定义 - - - - - 创建索引条件定义 - - - - - 创建更新条件定义 - - - - - 创建排序条件定义 - - - - - MongoDb配置 - - - - - 别名,同一种的业务数据库的可以有多个,但是每个的别名都不能相同 - - - - - 连接字符串 - - - - - 数据库名称 - - - - - MongoDbContext - - - - - 当前连接 - - - - - 当前操作数据库 - - - - - 企业ID - - - - - 构造方法 - - - - - - - - 检查数据库是否存在 - - - - - - - - 检查文档集是否存在 - - - - - - - - 获取文档集接口 - - - - - - - - - 根据企业名称和文档集类型构建 文档集名称 - - 返回文档集格式:{typeof(TDocument).Name}{corpId}, - - - - 企业ID - - - - - 根据企业ID获取,获取文档集接口 - - - - - - - - 检查文档集是否存在 - - 文档集名称 - - - - - 清空文档集数据 - - - - - - 销毁 - - - - - MongoDB 文件集扩展类 - - - - - 聚合默认选项 - - - - - 创建文档集 - - 文档集类型 - - 文档集名称 - - - - - 创建文档集索引,倒序 - - - - - - - - - - 插入一个 ,等同使用:IMongoCollection.InsertOne - - 文档集类型 - 文档集 - 文档对象 - 插入配置选项 - - - - 插入多个,等同使用: - IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - - 文档集类型 - 文档集 - 文档对象 - 插入配置选项 - - - - 构建更新操作定义 - - bsondocument文档 - - - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - - - 更新满足条件的第一条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - - - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - - - 更新满足条件的多条数据, - IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - - - - - - - - - - 根据更新字段表达式组装UpdateDefinitioons - - - - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 数据库实体类型 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - - 数据库实体类型 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 数据库实体类型 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - - 数据库实体类型 - - 更新条件 - 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 文档对象对象 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 文档对象对象 - 查询添加表达式 - - - - - 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 文档对象对象 - 查询添加表达式 - - - - - 删除满足条件的第一条数据,等同于 - IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 删除条件表达式 - - - - 批量删除满足条件的多条数据,等同于 - IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - - 文档对象类型 - 文档集操作接口 - 删除条件表达式 - - - - AggregateWithDefautSortOption - - - - - - - - - 可查询 - - - - - - - - 分页查询,统计总共多少条 - - 文档集类型 - 可查询器 - 页码,第几页,默认1 - 每页条数,默认10 - 总共多少条 - - - - - 分页查询,统计总共多少条,可以根据查询新对象的表达式,返回新对象集合 - - 文档集类型 - 新结构类型 - 可查询器 - 查询func,查询返回新对象的表达式 - 页码,第几页,默认1 - 每页条数,默认10 - 总共多少条 - - - - - 分页查询 - - 文档集类型 - 可查询器 - 页码,第几页,默认1 - 每页条数,默认10 - - - - - 分页查询,可以根据查询新对象的表达式,返回新对象集合 - - 文档集类型 - 新结构类型 - 可查询器 - 查询func,查询返回新对象的表达式 - 页码,第几页,默认1 - 每页条数,默认10 - - - - - 当condition为true,才会执行where表达式里面的条件 - - 文档集类型 - 可查询器 - 前置条件 - where表达式 - - - - - 当condition为true,才会执行where表达式里面的条件 - - 文档集类型 - 可查询器 - 前置条件 - where表达式 - - - - - 根据selectNewResultExp 表达式返回新的查询结果,最终要执行 必须ToList、Single、 Any - - - - - - - - - - - 根据selectNewResultExp 表达式返回新的查询结果,最终要执行 必须ToList、Single、 Any - - - - - - - - - - - 创建过滤条件定义 - - - - - - 创建索引条件定义 - - - - - - 创建更新条件定义 - - - - - - 创建排序条件定义 - - - - - - AddToSet 追加到数组 - - - - - - - - - AddToSet 追加到数组 - - - - - - - - - MongoDbContext 工厂 - - - - - 企业和别名的关系 - - - - - 别名和mongondb实例的对应关系 - - - - - 别名和连接配置关系 - - - - - MongonDbFactory - - - - - - 设置数据库连接配置 - - - - - - 根据企业ID获取MongoDb上下文对象 - - 企业ID - - - - - GetMongoDatabase - - - - - - - 获取所有的数据库操作对象 别名+数据库操作对象 - - - - - - 根据企业Id获取数据库别名,子类必须实现 - - - - - - 获取文档集接口 - - - 企业ID - - - - - diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMGRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMGRepository.cs deleted file mode 100644 index 241a6e2..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMGRepository.cs +++ /dev/null @@ -1,631 +0,0 @@ -using System.Linq.Expressions; -using MongoDB.Driver; -using MongoDB.Driver.Linq; - -namespace BPA.Component.MongoClient -{ - /// - /// MongoDb基础仓储 - /// - public abstract class BaseMGRepository : IMGRepository where TDocument : new() - { - /// - /// 当前企业(商户)Id - /// - public long CorpId { protected set; get; } - - /// - /// 当前MongoDB上下文 - /// - public MongoDbContext CurrMongoDbContext { protected set; get; } - - /// - /// 当前需要操作的文档集 - /// - public IMongoCollection CurrentCollection { protected set; get; } - - /// - /// MongoDbProvider - /// - public MongoDbProvider MongoDbProvider { protected set; get; } - - /// - /// 构造方法 - /// - /// - public BaseMGRepository(MongoDbProvider mongoDbProvider) - { - MongoDbProvider = mongoDbProvider; - } - - /// - /// 切换企业Id - /// - /// - public virtual void ChangeCorpId(long corpId) - { - CorpId = corpId; - CurrMongoDbContext = MongoDbProvider.GetDbContext(corpId); - CurrentCollection = CurrMongoDbContext.GetCollection(null); - } - - /// - /// 检查当前文档集 - /// - private void CheckCurrentCollection() - { - if (CurrentCollection == null) - throw new ArgumentNullException($"当前要操作的文档集为空,请调用{nameof(ChangeCorpId)}方法切换企业Id!"); - } - - #region 插入扩展 - - /// - /// 插入一个 ,等同使用:IMongoCollection.InsertOne - /// - /// 文档对象 - /// 插入配置选项 - public void InsertOne(TDocument document, InsertOneOptions? options = null) - { - CheckCurrentCollection(); - CurrentCollection.InsertOne(document, options); - } - - /// - /// 插入多个,等同使用: - /// IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - /// - /// 文档对象 - /// 插入配置选项 - public void InsertMany(IEnumerable documents, InsertManyOptions? options = null) - { - CheckCurrentCollection(); - CurrentCollection.InsertMany(documents, options); - } - - /// - /// 插入一个 ,等同使用:IMongoCollection.InsertOneAsync - /// - /// 文档对象 - /// 插入配置选项 - public Task InsertOneAsync(TDocument document, InsertOneOptions? options = null) - { - CheckCurrentCollection(); - return CurrentCollection.InsertOneAsync(document, options); - } - - /// - /// 插入多个,等同使用: - /// IMongoCollection.InsertManyAsync(IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - /// - /// 文档对象 - /// 插入配置选项 - public Task InsertManyAsync(IEnumerable documents, InsertManyOptions? options = null) - { - CheckCurrentCollection(); - return CurrentCollection.InsertManyAsync(documents, options); - } - - #endregion - - #region 更新扩展 - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - public UpdateResult UpdateOne(TDocument document, Expression> whereExpression, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOne(document, whereExpression, options); - } - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOneAsync(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - public Task UpdateOneAsync(TDocument document, Expression> whereExpression, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOneAsync(document, whereExpression, options); - } - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - public UpdateResult UpdateMany(TDocument document, Expression> whereExpression, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateMany(document, whereExpression, options); - } - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - public Task UpdateManyAsync(TDocument document, Expression> whereExpression, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateManyAsync(document, whereExpression, options); - } - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public UpdateResult UpdateOne(Expression> columnsExp, - Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOne(columnsExp, whereExpression); - } - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public Task UpdateOneAsync(Expression> columnsExp, - Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOneAsync(columnsExp, whereExpression); - } - - /// - /// 自定义更新字段和条件,更新单条符合条件的数据 - /// - /// - /// - /// - /// - public UpdateResult UpdateOne(FilterDefinition filter, UpdateDefinition update, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOne(filter, update, options); - } - - /// - /// 自定义更新字段和条件,更新单条符合条件的数据 - /// - /// - /// - /// - /// - public Task UpdateOneAsync(FilterDefinition filter, UpdateDefinition update, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateOneAsync(filter, update, options); - } - - - /// - /// 自定义更新字段和条件,更新条符合条件的数据 - /// - /// - /// - /// - /// - public UpdateResult UpdateMany(FilterDefinition filter, UpdateDefinition update, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateMany(filter, update, options); - } - - /// - /// 自定义更新字段和条件,更新条符合条件的数据 - /// - /// - /// - /// - /// - public Task UpdateManyAsync(FilterDefinition filter, - UpdateDefinition update, - UpdateOptions options = null) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateManyAsync(filter, update, options); - } - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public UpdateResult UpdateMany(Expression> columnsExp, - Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateMany(columnsExp, whereExpression); - } - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public Task UpdateManyAsync(Expression> columnsExp, - Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.UpdateManyAsync(columnsExp, whereExpression); - } - - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// - public ReplaceOneResult ReplaceOneById(TDocument document) - { - CheckCurrentCollection(); - return CurrentCollection.ReplaceOneById(document); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// - public Task ReplaceOneByIdAsync(TDocument document) - { - CheckCurrentCollection(); - return CurrentCollection.ReplaceOneByIdAsync(document); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// 查询添加表达式 - /// - public ReplaceOneResult ReplaceOne(TDocument document, Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.ReplaceOne(document, whereExpression); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// 查询添加表达式 - /// - public Task ReplaceOneAsync(TDocument document, - Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.ReplaceOneAsync(document, whereExpression); - } - - #endregion - - #region 删除扩展 - - /// - /// 删除满足条件的第一条数据,等同于 - /// IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - public DeleteResult DeleteOne(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.DeleteOne(whereExpression); - } - - /// - /// 删除满足条件的第一条数据,等同于 - /// IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - public Task DeleteOneAsync(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.DeleteOneAsync(whereExpression); - } - - /// - /// 批量删除满足条件的多条数据,等同于 - /// IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - public DeleteResult DeleteMany(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.DeleteMany(whereExpression); - } - - /// - /// 批量删除满足条件的多条数据,等同于 - /// IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - public Task DeleteManyAsync(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.DeleteManyAsync(whereExpression); - } - - #endregion - - #region 查询扩展 - - /// - /// 根据条件查询 - /// - /// - /// - /// - public IFindFluent Find(FilterDefinition filter, FindOptions? options) - { - CheckCurrentCollection(); - return CurrentCollection.Find(filter, options); - } - - /// - /// 根据条件查询 - /// - /// - /// - /// - public Task> FindAsync( - FilterDefinition filter, - FindOptions? options) - { - CheckCurrentCollection(); - return CurrentCollection.FindAsync(filter, options); - } - - /// - /// 可查询 - /// - /// - public IMongoQueryable Queryable() - { - CheckCurrentCollection(); - return CurrentCollection.Queryable(); - } - - /// - /// 可查询 根据条件 - /// - /// - /// - public IMongoQueryable Queryable(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression); - } - - /// - /// 可查询 根据条件 - /// - /// - /// - /// - public IMongoQueryable Queryable(Expression> whereExpression, - Expression> selectExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Select(selectExpression); - } - - /// - /// 根据条件判断是否存在 - /// - /// - /// - public bool Any(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Any(); - } - - /// - /// 根据ID获取entity - /// - /// - /// - public TDocument GetById(dynamic id) - { - CheckCurrentCollection(); - FilterDefinition filter = Builders.Filter.Eq("_id", id); - var find = CurrentCollection.Find(filter, null); - return find.FirstOrDefault(); - } - - /// - /// 根据ID获取entity - /// - /// - /// - public async Task GetByIdAsync(dynamic id) - { - CheckCurrentCollection(); - FilterDefinition filter = Builders.Filter.Eq("_id", id); - var find = await CurrentCollection.FindAsync(filter, null); - return find.FirstOrDefault(); - } - - /// - /// 根据ID获取entity - /// - /// - /// 需要返会的字段表达式 - /// - public TResult GetById(dynamic id, Expression> selectExpression) - { - CheckCurrentCollection(); - FilterDefinition filter = Builders.Filter.Eq("_id", id); - var find = CurrentCollection.Find(filter, null); - return find.Select(selectExpression).FirstOrDefault(); - } - - /// - /// 根据条件 获取第一条数据 - /// - /// 条件 - /// 返回的新对象选择表达式 - /// - public TResult? First(Expression> whereExpression, - Expression> selectExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Select(selectExpression).FirstOrDefault(); - } - - /// - /// 根据条件 获取第一条数据 - /// - /// 条件 - /// 返回的新对象选择表达式 - /// - public Task FirstAsync(Expression> whereExpression, - Expression> selectExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Select(selectExpression).FirstOrDefaultAsync(); - } - - /// - /// 根据条件 获取第一条数据 - /// - /// - /// - public TDocument? First(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).FirstOrDefault(); - } - - /// - /// 根据条件 获取第一条数据 - /// - /// - /// - public Task FirstAsync(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).FirstOrDefaultAsync(); - } - - /// - /// 根据条件获取集合 - /// - /// - /// - public List QueryList(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).ToList(); - } - - /// - /// 根据条件获取集合 - /// - /// - /// - public Task> QueryListAsync(Expression> whereExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).ToListAsync(); - } - - /// - /// 根据条件获取集合 - /// - /// - /// - /// - public List QueryList(Expression> whereExpression, - Expression> selectExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Select(selectExpression).ToList(); - } - - /// - /// 根据条件获取集合 - /// - /// - /// - /// - public Task> QueryListAsync(Expression> whereExpression, - Expression> selectExpression) - { - CheckCurrentCollection(); - return CurrentCollection.Queryable().Where(whereExpression).Select(selectExpression).ToListAsync(); - } - - #endregion - - #region 创建 查询 、索引、更新、排序 条件定义 - - /// - /// 创建过滤条件定义 - /// - public FilterDefinitionBuilder BuilderFilter() => Builders.Filter; - - /// - /// 创建索引条件定义 - /// - public IndexKeysDefinitionBuilder BuilderIndexKeys() => Builders.IndexKeys; - - /// - /// 创建更新条件定义 - /// - public UpdateDefinitionBuilder BuilderUpdate() => Builders.Update; - - /// - /// 创建排序条件定义 - /// - public SortDefinitionBuilder BuilderSort() => Builders.Sort; - - /// - /// Filter - /// - public FilterDefinitionBuilder Filter => Builders.Filter; - - /// - /// Update - /// - public UpdateDefinitionBuilder Update => Builders.Update; - - /// - /// Sort - /// - public SortDefinitionBuilder Sort => Builders.Sort; - - #endregion - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMongoDbClient.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMongoDbClient.cs new file mode 100644 index 0000000..31025e4 --- /dev/null +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/BaseMongoDbClient.cs @@ -0,0 +1,49 @@ +using System.Runtime.CompilerServices; +using Microsoft.Extensions.Logging; +using MongoDB.Driver.Core.Configuration; + +namespace BPA.Component.MongoClient; + +public class BaseMongoDbClient : MongoDB.Driver.MongoClient + where TMongoDbClient : BaseMongoDbClient +{ + /// + /// Logger + /// + private readonly ILogger _logger; + + /// + /// MongoConfig + /// + private static MongoConfig _config; + + /// + /// CurrentDatabaseName + /// + protected internal readonly string CurrentDatabaseName; + + /// + /// BaseMongoDbClient + /// + /// + /// + public BaseMongoDbClient(MongoConfig config, ILogger logger = null) + { + CurrentDatabaseName = config.DatabasesName; + _config = config; + _logger = logger; + } + + /// + /// BuildMongoConfig + /// + /// + /// + /// + protected static MongoConfig BuildMongoConfig(string connectionString, string databaseName) + { + _config = new MongoConfig {ConnectionString = connectionString, DatabasesName = databaseName}; + return _config; + } + +} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/IMGRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/IMGRepository.cs deleted file mode 100644 index 6c28a6c..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/IMGRepository.cs +++ /dev/null @@ -1,425 +0,0 @@ -using System.Linq.Expressions; -using MongoDB.Driver; -using MongoDB.Driver.Linq; - -namespace BPA.Component.MongoClient -{ - /// - /// MongoDB仓储接口 - /// - public interface IMGRepository where TDocument : new() - { - /// - /// 当前企业(商户)Id - /// - long CorpId { get; } - - /// - /// 切换企业Id - /// - /// - void ChangeCorpId(long corpId); - - /// - /// MongonDbProvider - /// - MongoDbProvider MongoDbProvider { get; } - - /// - /// 当前MongoDB上下文 - /// - MongoDbContext CurrMongoDbContext { get; } - - /// - /// 当前需要操作的文档集 - /// - IMongoCollection CurrentCollection { get; } - - #region 插入扩展 - - /// - /// 插入一个 ,等同使用:IMongoCollection.InsertOne - /// - /// 文档对象 - /// 插入配置选项 - void InsertOne(TDocument document, InsertOneOptions? options = null); - - /// - /// 插入多个,等同使用: - /// IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - /// - /// 文档对象 - /// 插入配置选项 - void InsertMany(IEnumerable documents, InsertManyOptions? options = null); - - /// - /// 插入一个 ,等同使用:IMongoCollection.InsertOneAsync - /// - /// 文档对象 - /// 插入配置选项 - Task InsertOneAsync(TDocument document, InsertOneOptions options = null); - - /// - /// 插入多个,等同使用: - /// IMongoCollection.InsertManyAsync(IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - /// - /// 文档对象 - /// 插入配置选项 - Task InsertManyAsync(IEnumerable documents, InsertManyOptions options = null); - - #endregion - - #region 更新扩展 - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - UpdateResult UpdateOne(TDocument document, Expression> whereExpression, UpdateOptions options = null); - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOneAsync(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - Task UpdateOneAsync(TDocument document, Expression> whereExpression, - UpdateOptions options = null); - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - UpdateResult UpdateMany(TDocument document, Expression> whereExpression, UpdateOptions options = null); - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - Task UpdateManyAsync(TDocument document, Expression> whereExpression, - UpdateOptions options = null); - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - UpdateResult UpdateOne(Expression> columnsExp, Expression> whereExpression); - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - Task UpdateOneAsync(Expression> columnsExp, Expression> whereExpression); - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - UpdateResult UpdateMany(Expression> columnsExp, Expression> whereExpression); - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - Task UpdateManyAsync(Expression> columnsExp, Expression> whereExpression); - - /// - /// 自定义更新字段和条件,更新单条符合条件的数据 - /// - /// - /// - /// - /// - UpdateResult UpdateOne(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null); - - /// - /// 自定义更新字段和条件,更新单条符合条件的数据 - /// - /// - /// - /// - /// - Task UpdateOneAsync(FilterDefinition filter, UpdateDefinition update, - UpdateOptions options = null); - - /// - /// 自定义更新字段和条件,更新条符合条件的数据 - /// - /// - /// - /// - /// - UpdateResult UpdateMany(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null); - - /// - /// 自定义更新字段和条件,更新条符合条件的数据 - /// - /// - /// - /// - /// - Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition update, - UpdateOptions options = null); - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// - ReplaceOneResult ReplaceOneById(TDocument document); - - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// - Task ReplaceOneByIdAsync(TDocument document); - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// 查询添加表达式 - /// - ReplaceOneResult ReplaceOne(TDocument document, Expression> whereExpression); - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象对象 - /// 查询添加表达式 - /// - Task ReplaceOneAsync(TDocument document, Expression> whereExpression); - - #endregion - - #region 删除扩展 - - /// - /// 删除满足条件的第一条数据,等同于 - /// IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - DeleteResult DeleteOne(Expression> whereExpression); - - /// - /// 删除满足条件的第一条数据,等同于 - /// IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - Task DeleteOneAsync(Expression> whereExpression); - - /// - /// 批量删除满足条件的多条数据,等同于 - /// IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - DeleteResult DeleteMany(Expression> whereExpression); - - /// - /// 批量删除满足条件的多条数据,等同于 - /// IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - /// - /// 删除条件表达式 - Task DeleteManyAsync(Expression> whereExpression); - - #endregion - - #region 查询扩展 - - /// - /// 根据条件查询 - /// - /// - /// - /// - IFindFluent Find(FilterDefinition filter, FindOptions options = null); - - /// - /// 根据条件查询 - /// - /// - /// - /// - Task> FindAsync(FilterDefinition filter, FindOptions options = null); - - /// - /// 可查询 - /// , 同步时用ToList, 异步时用 ToListAsync - /// - /// - IMongoQueryable Queryable(); - - /// - /// 可查询 根据条件 , 同步时用ToList, 异步时用 ToListAsync - /// - /// - /// - IMongoQueryable Queryable(Expression> whereExpression); - - /// - /// 可查询 根据条件 , 同步时用ToList , 异步时用 ToListAsync - /// - /// - /// - /// - IMongoQueryable Queryable(Expression> whereExpression, - Expression> selectExpression); - - /// - /// 根据条件判断是否存在 - /// - /// - /// - bool Any(Expression> whereExpression); - - /// - /// 根据ID获取entity - /// - /// - /// - TDocument GetById(dynamic id); - - /// - /// 根据ID获取entity - /// - /// - /// - Task GetByIdAsync(dynamic id); - - /// - /// 根据ID获取entity - /// - /// - /// 需要返回的字段表达式 - /// - TResult GetById(dynamic id, Expression> selectExpression); - - /// - /// 根据条件 获取第一条数据 - /// - /// 条件 - /// 返回的新对象选择表达式 - /// - TResult? First(Expression> whereExpression, Expression> selectExpression); - - /// - /// 根据条件 获取第一条数据 - /// - /// 条件 - /// 返回的新对象选择表达式 - /// - Task FirstAsync(Expression> whereExpression, - Expression> selectExpression); - - /// - /// 根据条件 获取第一条数据 - /// - /// - /// - TDocument? First(Expression> whereExpression); - - /// - /// 根据条件 获取第一条数据 - /// - /// - /// - Task FirstAsync(Expression> whereExpression); - - /// - /// 根据条件获取集合 - /// - /// - /// - List QueryList(Expression> whereExpression); - - /// - /// 根据条件获取集合 - /// - /// - /// - Task> QueryListAsync(Expression> whereExpression); - - /// - /// 根据条件获取集合 - /// - /// - /// - /// - List QueryList(Expression> whereExpression, - Expression> selectExpression); - - /// - /// 根据条件获取集合 - /// - /// - /// - /// - Task> QueryListAsync(Expression> whereExpression, - Expression> selectExpression); - - #endregion - - #region 创建 查询 、索引、更新、排序 条件定义 - - /// - /// Filter - /// - FilterDefinitionBuilder Filter { get; } - - /// - /// Update - /// - UpdateDefinitionBuilder Update { get; } - - /// - /// Sort - /// - SortDefinitionBuilder Sort { get; } - - /// - /// 创建过滤条件定义 - /// - FilterDefinitionBuilder BuilderFilter(); - - /// - /// 创建索引条件定义 - /// - IndexKeysDefinitionBuilder BuilderIndexKeys(); - - /// - /// 创建更新条件定义 - /// - UpdateDefinitionBuilder BuilderUpdate(); - - /// - /// 创建排序条件定义 - /// - SortDefinitionBuilder BuilderSort(); - - #endregion - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbConfig.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoConfig.cs similarity index 56% rename from src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbConfig.cs rename to src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoConfig.cs index 3f388f7..221ad0e 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbConfig.cs +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoConfig.cs @@ -3,20 +3,15 @@ /// /// MongoDb配置 /// - public class MongoDbConfig + public class MongoConfig { - /// - /// 别名,同一种的业务数据库的可以有多个,但是每个的别名都不能相同 - /// - public string Alias { set; get; } - /// /// 连接字符串 /// public string ConnectionString { set; get; } /// - /// 数据库名称 + /// 数据库名称 | 可空 /// public string DatabasesName { set; get; } } diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbContext.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbContext.cs deleted file mode 100644 index d929ea8..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbContext.cs +++ /dev/null @@ -1,177 +0,0 @@ -using BPA.Component.MongoClient.Conventions; -using MongoDB.Bson; -using MongoDB.Bson.Serialization; -using MongoDB.Bson.Serialization.Conventions; -using MongoDB.Bson.Serialization.Serializers; -using MongoDB.Driver; -using Newtonsoft.Json.Linq; - -namespace BPA.Component.MongoClient -{ - /// - /// MongoDbContext - /// - public class MongoDbContext : IDisposable - { - static MongoDbContext() - { - var serializer = new DateTimeSerializer(DateTimeKind.Local, BsonType.DateTime); - BsonSerializer.RegisterSerializer(typeof(DateTime), serializer); - BsonSerializer.RegisterSerializer(typeof(JObject), new JObjectSerializer()); - BsonSerializer.RegisterSerializer(typeof(JArray), new JArraySerializer()); - BsonSerializer.RegisterSerializer(typeof(Dictionary), new DictionarySerializerSerializer()); - BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128)); - BsonSerializer.RegisterSerializer(typeof(decimal?), - new NullableSerializer(new DecimalSerializer(BsonType.Decimal128))); - BsonSerializer.RegisterSerializationProvider(new BPASerializationProvider()); - - ConventionRegistry.Register("IgnoreExtraElements", - new ConventionPack - { - new IgnoreExtraElementsConvention(true), new BPACamelCaseElementNameConvention(), - new EnumRepresentationConvention(BsonType.String) - }, _ => true); - } - - /// - /// 当前连接 - /// - public readonly IMongoClient MongoClient; - - /// - /// 当前操作数据库 - /// - public readonly IMongoDatabase Database; - - /// - /// 企业ID - /// - public readonly long CorpId; - - /// - /// 构造方法 - /// - /// - /// - /// - public MongoDbContext(long corpId, IMongoClient mongoClient, IMongoDatabase database) - { - CorpId = corpId; - MongoClient = mongoClient; - Database = database; - } - - /// - /// 检查数据库是否存在 - /// - /// - /// - /// - public bool DatabaseExists(MongoDB.Driver.MongoClient mongoClient, string databaseName) - { - try - { - var dbNames = mongoClient.ListDatabases().ToList().Select(db => db.GetValue("name").AsString); - return dbNames.Contains(databaseName); - } - catch - { - return true; - } - } - - /// - /// 检查文档集是否存在 - /// - /// - /// - /// - public bool CollectionExists(IMongoDatabase mongoDatabase, string collectionName) - { - var options = new ListCollectionsOptions - { - Filter = Builders.Filter.Eq("name", collectionName) - }; - return mongoDatabase.ListCollections(options).ToEnumerable().Any(); - } - - /// - /// 获取文档集接口 - /// - /// - /// - /// - /// - public IMongoCollection GetCollection(string collectionName, - MongoCollectionSettings? settings) - { - return Database.GetCollection(collectionName, settings); - } - - - /// - /// 根据企业名称和文档集类型构建 文档集名称 - /// - /// 返回文档集格式:{typeof(TDocument).Name}{corpId}, - /// - /// - /// - /// 企业ID - /// - public string BuildCollectionName(long corpId) - { - return $"{typeof(TDocument).Name}{corpId}"; - } - - /// - /// 根据企业ID获取,获取文档集接口 - /// - /// - /// - /// - public IMongoCollection GetCollection(MongoCollectionSettings? settings) - { - var collectionName = BuildCollectionName(CorpId); - return GetCollection(collectionName, settings); - } - - - /// - /// 检查文档集是否存在 - /// - /// 文档集名称 - /// - public bool CollectionExists(string collectionName) - { - var options = new ListCollectionsOptions - { - Filter = Builders.Filter.Eq("name", collectionName) - }; - return Database.ListCollections(options).ToEnumerable().Any(); - } - - /// - /// 清空文档集数据 - /// - /// - public IMongoCollection ClearCollection() - { - var collectionName = BuildCollectionName(CorpId); - //删除文档集 - Database.DropCollection(collectionName); - if (!CollectionExists(Database, collectionName)) - { - this.CreateCollection(collectionName); - } - - return Database.GetCollection(collectionName); - } - - /// - /// 销毁 - /// - public void Dispose() - { - } - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbExtensions.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbExtensions.cs deleted file mode 100644 index e56bd88..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbExtensions.cs +++ /dev/null @@ -1,714 +0,0 @@ -using System.Linq.Expressions; -using MongoDB.Bson; -using MongoDB.Driver; -using MongoDB.Driver.Linq; - -namespace BPA.Component.MongoClient -{ - /// - /// MongoDB 文件集扩展类 - /// - public static class MongoDbExtensions - { - /// - /// 聚合默认选项 - /// - public static readonly AggregateOptions DefaultAggregateOptions = new AggregateOptions {AllowDiskUse = true}; - - #region 文档集操作扩展 - - /// - /// 创建文档集 - /// - /// 文档集类型 - /// - /// 文档集名称 - /// - public static void CreateCollection(this MongoDbContext mongoDbContent, string collectionName, - CreateCollectionOptions options = null) - { - mongoDbContent.Database.CreateCollection(collectionName, options); - } - - /// - /// 创建文档集索引,倒序 - /// - /// - /// - /// - /// - /// - public static void CreateIndex(this IMongoCollection collection, string[] indexFields, - CreateIndexModel model, CreateOneIndexOptions options = null) - { - if (indexFields == null) - return; - var indexKeys = Builders.IndexKeys; - IndexKeysDefinition keys = null; - if (indexFields.Length > 0) - { - keys = indexKeys.Descending(indexFields[0]); - } - - for (var i = 1; i < indexFields.Length; i++) - { - var strIndex = indexFields[i]; - keys = keys.Descending(strIndex); - } - - if (keys != null) - { - collection.Indexes.CreateOne(model, options); - } - } - - #endregion - - #region 插入扩展 - - /// - /// 插入一个 ,等同使用:IMongoCollection.InsertOne - /// - /// 文档集类型 - /// 文档集 - /// 文档对象 - /// 插入配置选项 - public static void InsertOne(this IMongoCollection collection, TDocument document, - InsertOneOptions options = null) - { - collection.InsertOne(document, options, default); - } - - /// - /// 插入多个,等同使用: - /// IMongoCollection.InsertMany(IClientSessionHandle, IEnumerable{TDocument}, InsertManyOptions, CancellationToken) - /// - /// 文档集类型 - /// 文档集 - /// 文档对象 - /// 插入配置选项 - public static void InsertMany(this IMongoCollection collection, - IEnumerable documents, - InsertManyOptions options = null) - { - collection.InsertMany(documents, options, default); - } - - #endregion - - #region 更新扩展 - - /// - /// 构建更新操作定义 - /// - /// bsondocument文档 - /// - /// - private static List> BuildUpdateDefinition(BsonDocument document, string parent) - { - var updates = new List>(); - foreach (var element in document.Elements) - { - var key = parent == null ? element.Name : $"{parent}.{element.Name}"; - //子元素是对象 - if (element.Value.IsBsonDocument) - { - updates.AddRange(BuildUpdateDefinition(element.Value.ToBsonDocument(), key)); - } - //子元素是对象数组 - else if (element.Value.IsBsonArray) - { - var arrayDocs = element.Value.AsBsonArray; - var i = 0; - foreach (var doc in arrayDocs) - { - if (doc.IsBsonDocument) - { - updates.AddRange(BuildUpdateDefinition(doc.ToBsonDocument(), key + $".{i}")); - } - else - { - updates.Add(Builders.Update.Set(f => f[key], element.Value)); - continue; - } - - i++; - } - } - //子元素是其他 - else - { - updates.Add(Builders.Update.Set(f => f[key], element.Value)); - } - } - - return updates; - } - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - /// - /// - public static UpdateResult UpdateOne(this IMongoCollection collection, - TDocument document, - Expression> whereExpression, - UpdateOptions options = null) - { - var bsonDocument = document.ToBsonDocument(); - bsonDocument.Remove("_id"); - BsonDocument update = new BsonDocument - { - {"$set", bsonDocument} - }; - return collection.UpdateOne(whereExpression, update, options); - } - - /// - /// 更新满足条件的第一条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument}, UpdateOptions, CancellationToken) - /// - /// - /// - /// - /// - /// - public static Task UpdateOneAsync(this IMongoCollection collection, - TDocument document, - Expression> whereExpression, - UpdateOptions options = null) - { - var bsonDocument = document.ToBsonDocument(); - bsonDocument.Remove("_id"); - BsonDocument update = new BsonDocument - { - {"$set", bsonDocument} - }; - return collection.UpdateOneAsync(whereExpression, update, options); - } - - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - /// - /// - public static UpdateResult UpdateMany(this IMongoCollection collection, - TDocument document, - Expression> whereExpression, - UpdateOptions options = null) - { - var bsonDocument = document.ToBsonDocument(); - bsonDocument.Remove("_id"); - BsonDocument update = new BsonDocument - { - {"$set", bsonDocument} - }; - return collection.UpdateMany(whereExpression, update, options); - } - - /// - /// 更新满足条件的多条数据, - /// IMongoCollection.UpdateOne(FilterDefinition{TDocument}, UpdateDefinition{TDocument},UpdateOptions, CancellationToken) - /// - /// - /// - /// - /// - /// - public static Task UpdateManyAsync(this IMongoCollection collection, - TDocument document, - Expression> whereExpression, - UpdateOptions options = null) - { - var bsonDocument = document.ToBsonDocument(); - bsonDocument.Remove("_id"); - BsonDocument update = new BsonDocument - { - {"$set", bsonDocument} - }; - return collection.UpdateManyAsync(whereExpression, update, options); - } - - - /// - /// 根据更新字段表达式组装UpdateDefinitioons - /// - /// - /// - /// - private static List> BuildUpdateDefinitioonsByExpression( - MemberInitExpression param) - { - var fieldList = new List>(); - foreach (var item in param.Bindings) - { - var propertyName = item.Member.Name; - if (propertyName == "_id" || propertyName == "Id") - continue; - object propertyValue = null; - if (!(item is MemberAssignment memberAssignment)) - continue; - if (memberAssignment.Expression.NodeType == ExpressionType.Constant) - { - if (memberAssignment.Expression is ConstantExpression constantExpression) - propertyValue = constantExpression.Value; - } - else - { - if (memberAssignment.Expression is MethodCallExpression methodCallExpression2) - { - if (methodCallExpression2.Method.Name == "AddToSet") - { - var argument = methodCallExpression2.Arguments[1]; - if (argument is ConstantExpression constantExpression) - { - fieldList.Add( - Builders.Update.AddToSet(propertyName, constantExpression.Value)); - } - else - { - propertyValue = Expression.Lambda(argument, null).Compile().DynamicInvoke(); - if (propertyValue is IEnumerable lsArg) - { - fieldList.Add(Builders.Update.AddToSetEach(propertyName, lsArg)); - } - else - { - fieldList.Add(Builders.Update.AddToSet(propertyName, propertyValue)); - } - } - - continue; - } - } - } - - propertyValue = Expression.Lambda(memberAssignment.Expression, null).Compile().DynamicInvoke(); - fieldList.Add(Builders.Update.Set(propertyName, propertyValue)); - } - - return fieldList; - } - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 数据库实体类型 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public static UpdateResult UpdateOne(this IMongoCollection collection, - Expression> columnsExp, - Expression> whereExpression) - { - if (!(columnsExp.Body is MemberInitExpression param)) - throw new ArgumentException($"{nameof(columnsExp)}错误,更新字段表达式示例: x=>new TDocument{{ F1 = 1,F2 = 2 }}"); - List> fieldList = BuildUpdateDefinitioonsByExpression(param); - return collection.UpdateOne(whereExpression, Builders.Update.Combine(fieldList)); - } - - /// - /// 自定义字段更新 更新满足条件的第一条数据,实体键_id不允许更新 - /// - /// 数据库实体类型 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public static Task UpdateOneAsync(this IMongoCollection collection, - Expression> columnsExp, - Expression> whereExpression) - { - if (!(columnsExp.Body is MemberInitExpression param)) - throw new ArgumentException($"{nameof(columnsExp)}错误,更新字段表达式示例: x=>new TDocument{{ F1 = 1,F2 = 2 }}"); - List> fieldList = BuildUpdateDefinitioonsByExpression(param); - return collection.UpdateOneAsync(whereExpression, Builders.Update.Combine(fieldList)); - } - - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 数据库实体类型 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public static UpdateResult UpdateMany(this IMongoCollection collection, - Expression> columnsExp, - Expression> whereExpression) - { - if (!(columnsExp.Body is MemberInitExpression param)) - throw new ArgumentException($"{nameof(columnsExp)}错误,更新字段表达式示例: x=>new TDocument{{ F1 = 1,F2 = 2 }}"); - List> fieldList = BuildUpdateDefinitioonsByExpression(param); - return collection.UpdateMany(whereExpression, Builders.Update.Combine(fieldList)); - } - - /// - /// 自定义字段更新 更新满足条件的多条数据,实体键_id不允许更新 - /// - /// 数据库实体类型 - /// - /// 更新条件 - /// 更新字段表达式:x=>new TDocument{ F1=1,F2=2 } - /// - public static Task UpdateManyAsync(this IMongoCollection collection, - Expression> columnsExp, - Expression> whereExpression) - { - if (!(columnsExp.Body is MemberInitExpression param)) - throw new ArgumentException($"{nameof(columnsExp)}错误,更新字段表达式示例: x=>new TDocument{{ F1 = 1,F2 = 2 }}"); - List> fieldList = BuildUpdateDefinitioonsByExpression(param); - return collection.UpdateManyAsync(whereExpression, Builders.Update.Combine(fieldList)); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 文档对象对象 - /// - public static ReplaceOneResult ReplaceOneById(this IMongoCollection collection, - TDocument document) - { - var id = new ObjectId(typeof(TDocument).GetProperty("Id").GetValue(document).ToString()); - return collection.ReplaceOne(new BsonDocument("_id", id), document); - } - - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 Id,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 文档对象对象 - /// - public static Task ReplaceOneByIdAsync(this IMongoCollection collection, - TDocument document) - { - var id = new ObjectId(typeof(TDocument).GetProperty("Id").GetValue(document).ToString()); - return collection.ReplaceOneAsync(new BsonDocument("_id", id), document); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 文档对象对象 - /// 查询添加表达式 - /// - public static ReplaceOneResult ReplaceOne(this IMongoCollection collection, - TDocument document, - Expression> whereExpression) - { - return collection.ReplaceOne(whereExpression, document); - } - - /// - /// 异步覆盖更新满足条件的第一条数据,主键字段名称必须是 ID,等同 - /// IMongoCollection.ReplaceOne(FilterDefinition{TDocument}, TDocument, ReplaceOptions, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 文档对象对象 - /// 查询添加表达式 - /// - public static Task ReplaceOneAsync(this IMongoCollection collection, - TDocument document, - Expression> whereExpression) - { - return collection.ReplaceOneAsync(whereExpression, document); - } - - #endregion - - #region 删除扩展 - - /// - /// 删除满足条件的第一条数据,等同于 - /// IMongoCollection.DeleteOne(FilterDefinition{TDocument}, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 删除条件表达式 - public static DeleteResult DeleteOne(this IMongoCollection collection, - Expression> whereExpression) - { - return collection.DeleteOne(whereExpression, null, default); - } - - /// - /// 批量删除满足条件的多条数据,等同于 - /// IMongoCollection.DeleteMany(FilterDefinition{TDocument}, CancellationToken) - /// - /// 文档对象类型 - /// 文档集操作接口 - /// 删除条件表达式 - public static DeleteResult DeleteMany(this IMongoCollection collection, - Expression> whereExpression) - { - return collection.DeleteMany(whereExpression, null, default); - } - - #endregion - - #region 查询扩展 - - /// - /// AggregateWithDefautSortOption - /// - /// - /// - /// - /// - public static IAggregateFluent AggregateWithDefautSortOption( - this IMongoCollection collection, - Action optionsAction = null) - { - var options = new AggregateOptions - { - Collation = new Collation(locale: "zh", numericOrdering: true), - AllowDiskUse = true - }; - if (optionsAction != null) - optionsAction(options); - return collection.Aggregate(options); - } - - /// - /// 可查询 - /// - /// - /// - /// - public static IMongoQueryable Queryable(this IMongoCollection collection) - { - return collection.AsQueryable(DefaultAggregateOptions); - } - - /// - /// 分页查询,统计总共多少条 - /// - /// 文档集类型 - /// 可查询器 - /// 页码,第几页,默认1 - /// 每页条数,默认10 - /// 总共多少条 - /// - public static List Pagination(this IQueryable queryable, int pageIndex, - int pageSize, - out int total) - { - pageIndex = pageIndex < 0 ? 1 : pageIndex; - pageSize = pageSize < 0 ? 10 : pageSize; - total = queryable.Count(); - return queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); - } - - /// - /// 分页查询,统计总共多少条,可以根据查询新对象的表达式,返回新对象集合 - /// - /// 文档集类型 - /// 新结构类型 - /// 可查询器 - /// 查询func,查询返回新对象的表达式 - /// 页码,第几页,默认1 - /// 每页条数,默认10 - /// 总共多少条 - /// - public static List Pagination(this IQueryable queryable, - Expression> selector, int pageIndex, int pageSize, out int total) - { - pageIndex = pageIndex < 0 ? 1 : pageIndex; - pageSize = pageSize < 0 ? 10 : pageSize; - total = queryable.Count(); - return queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(selector).ToList(); - } - - /// - /// 分页查询 - /// - /// 文档集类型 - /// 可查询器 - /// 页码,第几页,默认1 - /// 每页条数,默认10 - /// - public static List Pagination(this IQueryable queryable, int pageIndex, - int pageSize) - { - pageIndex = pageIndex < 0 ? 1 : pageIndex; - pageSize = pageSize < 0 ? 10 : pageSize; - return queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); - } - - /// - /// 分页查询,可以根据查询新对象的表达式,返回新对象集合 - /// - /// 文档集类型 - /// 新结构类型 - /// 可查询器 - /// 查询func,查询返回新对象的表达式 - /// 页码,第几页,默认1 - /// 每页条数,默认10 - /// - public static List Pagination(this IMongoQueryable queryable, - Expression> selector, int pageIndex, int pageSize) - { - pageIndex = pageIndex < 0 ? 1 : pageIndex; - pageSize = pageSize < 0 ? 10 : pageSize; - return queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(selector).ToList(); - } - - /// - /// 当condition为true,才会执行where表达式里面的条件 - /// - /// 文档集类型 - /// 可查询器 - /// 前置条件 - /// where表达式 - /// - public static IMongoQueryable WhereIF(this IMongoQueryable queryable, - bool beforeCondition, - Expression> whereExpression) - { - if (beforeCondition) - return queryable.Where(whereExpression); - return queryable; - } - - /// - /// 当condition为true,才会执行where表达式里面的条件 - /// - /// 文档集类型 - /// 可查询器 - /// 前置条件 - /// where表达式 - /// - public static IQueryable WhereIF(this IQueryable queryable, - bool beforeCondition, - Expression> whereExpression) - { - if (beforeCondition) - return queryable.Where(whereExpression); - return queryable; - } - - - /// - /// 根据selectNewResultExp 表达式返回新的查询结果,最终要执行 必须ToList、Single、 Any - /// - /// - /// - /// - /// - /// - /// - public static IFindFluent As( - this IFindFluent find, - Expression> selectNewResultExp) - { - return find.Project(selectNewResultExp); - } - - /// - /// 根据selectNewResultExp 表达式返回新的查询结果,最终要执行 必须ToList、Single、 Any - /// - /// - /// - /// - /// - /// - /// - public static IFindFluent Select( - this IFindFluent find, - Expression> selectNewResultExp) - { - return find.Project(selectNewResultExp); - } - - #endregion - - #region 创建 查询 、索引、更新、排序 条件定义 - - /// - /// 创建过滤条件定义 - /// - /// - public static FilterDefinitionBuilder BuilderFilter( - this IMongoCollection collection) - { - return Builders.Filter; - } - - /// - /// 创建索引条件定义 - /// - /// - public static IndexKeysDefinitionBuilder BuilderIndexKeys( - this IMongoCollection collection) - { - return Builders.IndexKeys; - } - - /// - /// 创建更新条件定义 - /// - /// - public static UpdateDefinitionBuilder BuilderUpdate( - this IMongoCollection collection) - { - return Builders.Update; - } - - /// - /// 创建排序条件定义 - /// - /// - public static SortDefinitionBuilder BuilderSort( - this IMongoCollection collection) - { - return Builders.Sort; - } - - #endregion - - /// - /// AddToSet 追加到数组 - /// - /// - /// - /// - /// - public static List AddToSet(this List source, T item) - { - return new List {item}; - } - - /// - /// AddToSet 追加到数组 - /// - /// - /// - /// - /// - public static List AddToSet(this List source, List items) - { - return items; - } - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbProvider.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbProvider.cs deleted file mode 100644 index 0875695..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/MongoDbProvider.cs +++ /dev/null @@ -1,138 +0,0 @@ -using MongoDB.Driver; - -namespace BPA.Component.MongoClient -{ - /// - /// MongoDbContext 工厂 - /// - public abstract class MongoDbProvider - { - /// - /// 企业和别名的关系 - /// - protected readonly Dictionary CorpWithMongoDbContexts = new(); - - /// - /// 别名和mongondb实例的对应关系 - /// - protected readonly Dictionary AliasWithMongoDbContexts = new(); - - /// - /// 别名和连接配置关系 - /// - public IReadOnlyDictionary AliasConfig { private set; get; } - - /// - /// MongonDbFactory - /// - /// - public MongoDbProvider(List mongoDbConfigs) - { - SetMongoDbConfigs(mongoDbConfigs); - } - - /// - /// 设置数据库连接配置 - /// - /// - public void SetMongoDbConfigs(List mongoDbConfigs) - { - lock (this) - { - var dic = new Dictionary(); - foreach (var config in mongoDbConfigs) - { - if (dic.ContainsKey(config.Alias)) - throw new ArgumentException($"数据库{this.GetType().Name}的配置别名[{config.Alias}]出现重复"); - dic.Add(config.Alias, config); - } - - AliasConfig = dic; - } - } - - /// - /// 根据企业ID获取MongoDb上下文对象 - /// - /// 企业ID - /// - public virtual MongoDbContext GetDbContext(long corpId) - { - if (CorpWithMongoDbContexts.ContainsKey(corpId)) - return CorpWithMongoDbContexts[corpId]; - lock (CorpWithMongoDbContexts) - { - if (CorpWithMongoDbContexts.ContainsKey(corpId)) - return CorpWithMongoDbContexts[corpId]; - var dbAlias = GetDbAliasByCropId(corpId); - if (dbAlias == null) - throw new ArgumentException($"无法获取到企业[{corpId}]的{this.GetType().Name}数据库别名!"); - if (!AliasConfig.ContainsKey(dbAlias)) - throw new ArgumentException($"无法获取到企业[{corpId}]的{this.GetType().Name}数据库别名[{dbAlias}]对应的数据库连接!"); - var databases = GetMongoDatabase(dbAlias); - return CorpWithMongoDbContexts[corpId] = new MongoDbContext(corpId, databases.Client, databases); - } - } - - /// - /// GetMongoDatabase - /// - /// - /// - public IMongoDatabase GetMongoDatabase(string dbAlias) - { - IMongoDatabase mongoDatabase = null; - lock (AliasWithMongoDbContexts) - { - if (AliasWithMongoDbContexts.ContainsKey(dbAlias)) - mongoDatabase = AliasWithMongoDbContexts[dbAlias]; - else - { - var mongoDbConfig = AliasConfig[dbAlias]; - var client = new MongoDB.Driver.MongoClient(mongoDbConfig.ConnectionString); - mongoDatabase = client.GetDatabase(mongoDbConfig.DatabasesName); - AliasWithMongoDbContexts[dbAlias] = mongoDatabase; - } - } - - return mongoDatabase; - } - - /// - /// 获取所有的数据库操作对象 别名+数据库操作对象 - /// - /// - public IReadOnlyDictionary GetMongoDatabases() - { - if (AliasConfig.Count != AliasWithMongoDbContexts.Count) - { - foreach (var dbAlias in AliasConfig.Keys) - { - GetMongoDatabase(dbAlias); - } - } - - return AliasWithMongoDbContexts; - } - - /// - /// 根据企业Id获取数据库别名,子类必须实现 - /// - /// - protected abstract string GetDbAliasByCropId(long corpId); - - /// - /// 获取文档集接口 - /// - /// - /// 企业ID - /// - /// - public IMongoCollection GetCollection(long cropId, - MongoCollectionSettings settings = null) - { - MongoDbContext dbContext = GetDbContext(cropId); - return dbContext.GetCollection(settings); - } - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/BaseMongoDbRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/BaseMongoDbRepository.cs new file mode 100644 index 0000000..4df7b25 --- /dev/null +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/BaseMongoDbRepository.cs @@ -0,0 +1,99 @@ +using BPA.Component.MongoClient.Conventions; +using MongoDB.Bson; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Serializers; +using MongoDB.Driver; +using Newtonsoft.Json.Linq; + +namespace BPA.Component.MongoClient.Repository; + +/// +/// MongoDb基础仓储 +/// +public class BaseMongoDbRepository : IBaseMongoDbRepository + where TMongoDbClient : BaseMongoDbClient + where TDocument : class, new() +{ + /// + /// MongoClient + /// + public MongoDB.Driver.MongoClient _mongoDbClient { get; } + + /// + /// _Database + /// + private readonly IMongoDatabase _database; + + /// + /// _Collection + /// + private IMongoCollection _collection; + + /// + /// 构造函数 + /// +#pragma warning disable CS8618 + internal BaseMongoDbRepository() +#pragma warning restore CS8618 + { + } + + /// + /// 构造方法 + /// + public BaseMongoDbRepository(BaseMongoDbClient mongoDbClient) + { + _mongoDbClient = mongoDbClient; + _database = _mongoDbClient.GetDatabase(mongoDbClient.CurrentDatabaseName); + + var serializer = new DateTimeSerializer(DateTimeKind.Local, BsonType.DateTime); + BsonSerializer.RegisterSerializer(typeof(DateTime), serializer); + BsonSerializer.RegisterSerializer(typeof(JObject), new JObjectSerializer()); + BsonSerializer.RegisterSerializer(typeof(JArray), new JArraySerializer()); + BsonSerializer.RegisterSerializer(typeof(Dictionary), new DictionarySerializerSerializer()); + BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128)); + BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer(new DecimalSerializer(BsonType.Decimal128))); + BsonSerializer.RegisterSerializationProvider(new BPASerializationProvider()); + + ConventionRegistry.Register("IgnoreExtraElements", + new ConventionPack + { + new IgnoreExtraElementsConvention(true), new BPACamelCaseElementNameConvention(), + new EnumRepresentationConvention(BsonType.String) + }, _ => true); + } + + /// + /// 变更集合 + /// + /// + public virtual void ChangeCollection(string collectionName) + { + _collection = _database.GetCollection(collectionName); + } + + /// + /// 检查当前文档集 + /// + private void Checkcollection() + { + if (_collection == null) + { + throw new ArgumentNullException($"当前要操作的文档集为空,请调用{nameof(ChangeCollection)}方法切换集合文档"); + } + } + + /// + /// 插入一个 + /// + /// + /// + /// + public async Task AddAsync(TDocument document) where TDocument : class, new() + { + var coll = _database.GetCollection(document.GetType().Name); + await coll.InsertOneAsync(document); + return 1; + } +} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/IBaseMongoDbRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/IBaseMongoDbRepository.cs new file mode 100644 index 0000000..256f763 --- /dev/null +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClient/Repository/IBaseMongoDbRepository.cs @@ -0,0 +1,12 @@ +using MongoDB.Driver; + +namespace BPA.Component.MongoClient.Repository +{ + /// + /// MongoDB仓储接口 + /// + public interface IBaseMongoDbRepository where TDocument : class, new() + { + MongoDB.Driver.MongoClient _mongoDbClient { get; } + } +} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/BPA.Component.MongoClientTester.csproj b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/BPA.Component.MongoClientTester.csproj index d2fa06c..fcb49e3 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/BPA.Component.MongoClientTester.csproj +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/BPA.Component.MongoClientTester.csproj @@ -5,10 +5,19 @@ enable enable default + Exe - + + + + + + + + + diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Program.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Program.cs index 862b75d..2e6a26a 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Program.cs +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Program.cs @@ -1,771 +1,61 @@ -// using BPA.Component.Extensions; -// using BPA.Component.MongoClient; -// using BPA.Component.MongoClientTester.Models; -// using BPA.Component.MongoClientTester.Repositorys; -// using MongoDB.Driver; -// -// namespace BPA.Component.MongoClientTester -// { -// internal class Program -// { -// private static readonly MongoDbConfig TestDbConfig = new MongoDbConfig -// { -// ConnectionString = "mongodb://root:a5014e2c9c5890d517179be4a5c9f9ac@192.168.0.150:27017/?authSource=admin", -// DatabasesName = "test", -// Alias = "crm-test-01" -// }; -// -// private static List _redisCluster = new List -// { -// "192.168.0.149:6380,poolsize=50,ssl=false,writeBuffer=10240", -// "192.168.0.147:6380,poolsize=50,ssl=false,writeBuffer=10240", -// "192.168.0.150:6380,poolsize=50,ssl=false,writeBuffer=10240" -// }; -// -// private static readonly long corpId = 10000; -// -// private static void Main(string[] args) -// { -// Console.WriteLine("1=测试Provider,2=测试Repository,3=TestWatch"); -// var cmd = Console.ReadLine(); -// switch (cmd) -// { -// case "1": -// TestMongonDbProvider(); -// break; -// case "2": -// TestRepository(); -// break; -// default: -// Console.WriteLine("命令错误"); -// break; -// } -// -// Console.ReadLine(); -// } -// -// -// //创建provider -// private static TestMongoDbProvider _testMongoDbProvider = -// new TestMongoDbProvider(new List {TestDbConfig}); -// -// static void TestWatchMock() -// { -// var corpInfoRepository = new CorpInfoRepository(_testMongoDbProvider); -// //必须切换企业ID -// corpInfoRepository.ChangeCorpId(corpId); -// -// #region 插入 -// -// var insertCorpInfos = new List(); -// for (var i = 0; i < 10000; i++) -// { -// insertCorpInfos.Add(new CorpInfo -// { -// CorpId = corpId, -// Id = BPAUniqueIdBulder.NextLong(), -// Phones = new List {$"1921682012{i}"}, -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, -// Address = ",''''''''''' %%%%天府大道天府三街", Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = null, -// No = $"sun{i}", -// Tags = new Dictionary -// { -// {"string", $"string{i}"}, -// {"int", 10 + i}, -// {"double", 20.00 + 1}, -// {"datetime", DateTime.Now.AddMinutes(i)}, -// {"bool", i % 2}, -// } -// }); -// } -// -// Thread.Sleep(1000); -// //批量插入 -// corpInfoRepository.InsertMany(insertCorpInfos); -// -// #endregion -// -// #region 更新 -// -// Thread.Sleep(1000); -// corpInfoRepository.UpdateMany(x => new CorpInfo -// { -// Phones = x.Phones.AddToSet("sss ' ,\" \\ \\\\ $ @@@ ") -// }, x => x.No.StartsWith("sun")); -// -// #endregion -// -// return; -// -// #region 删除 -// -// Thread.Sleep(1000); -// var data = DateTime.Now.AddMinutes(5); -// corpInfoRepository.DeleteMany(x => x.CreateDate <= data); -// -// #endregion -// } -// -// static void TestRepository() -// { -// //创建provider -// var testMongonDbProvider = new TestMongoDbProvider(new List {TestDbConfig}); -// ICorpInfoRepository corpInfoRepository = new CorpInfoRepository(testMongonDbProvider); -// -// //必须切换企业ID -// corpInfoRepository.ChangeCorpId(corpId); -// -// //清空 测试数据清空下,一般清空是不要用到这个方法 -// corpInfoRepository.CurrMongoDbContext.ClearCollection(); -// -// -// #region 插入 -// -// var tags = new Dictionary -// { -// {"datetime", DateTime.Now}, -// {"array0-1", new object[] {1, true, 66.2D, EnumEmployeeStatusType.Normal, DateTime.Now, ""}}, -// {"array00", null}, -// {"array01", new List {"sss", "bbb"}}, -// {"array02", new List {new string[] {"1", "2"}, new string[] {"3", "4"}}}, -// { -// "array03", -// new List -// { -// new CorpAddressInfo -// {Address = "ss", Id = DateTime.Now.Ticks, Latitude = 1, Longitude = 2, Remark = ""} -// } -// }, -// }; -// // tags = Newtonsoft.Json.JsonConvert.DeserializeObject>(tags.ToJson()); -// //插入单个 -// corpInfoRepository.InsertOneAsync(new CorpInfo -// { -// EnumEmployee = EnumEmployeeStatusType.Normal, -// CorpId = corpId, -// Id = BPAUniqueIdBulder.NextLong(), -// DB = long.MaxValue, -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Name = "太阳国1", -// No = "sun1", -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Tags = tags, -// Phones = new List {"1921682012", "1921682012", "1921682012"} -// }); -// -// corpInfoRepository.InsertOneAsync(new CorpInfo -// { -// CorpId = corpId, -// Id = BPAUniqueIdBulder.NextLong(), -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = "太阳国2", -// No = "sun2", -// Tags = new Dictionary -// { -// {"string", "string"}, -// {"int", 10}, -// {"double", 20.00}, -// {"datetime", DateTime.Now}, -// {"bool", true}, -// {"array0-1", new object[] {1, true, 66.2D, EnumEmployeeStatusType.Normal, DateTime.Now, ""}}, -// { -// "复杂的", -// new List -// { -// new CorpAddressInfo -// { -// Id = DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// } -// } -// }, -// Phones = new List {"1921682013", "1921682014", "1921682015"}, -// Ids = new List {122238324489609220, 124675751317626880, 168259568508141570, 229039077946073100} -// }); -// -// Task.WaitAll(); -// -// var all = corpInfoRepository.Queryable().ToList(); -// -// return; -// -// var insertCorpInfos = new List(); -// for (var i = 3; i < 10; i++) -// { -// insertCorpInfos.Add(new CorpInfo -// { -// CorpId = corpId, -// Id = BPAUniqueIdBulder.NextLong(), -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, -// Address = ",''''''''''' %%%%天府大道天府三街", Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = null, -// No = $"sun{i}", -// Tags = new Dictionary -// { -// {"string", $"string{i}"}, -// {"int", 10 + i}, -// {"double", 20.00 + 1}, -// {"datetime", DateTime.Now.AddMinutes(i)}, -// {"bool", i % 2}, -// } -// }); -// } -// -// Console.ReadLine(); -// //批量插入 -// corpInfoRepository.InsertMany(insertCorpInfos); -// -// #endregion -// -// var filters = corpInfoRepository.BuilderFilter(); -// var filterDefinitions = new List> -// { -// filters.Eq("No", "sun1") -// }; -// FilterDefinition filterDefinition = filters.And(filterDefinitions); -// var finder = corpInfoRepository.Find(filterDefinition); -// var result = finder.FirstOrDefault(); -// Console.WriteLine("使用 Find 进行查询:"); -// Console.WriteLine(result.ToJson()); -// -// -// #region 查询 Queryable 强烈推荐使用 -// -// Console.WriteLine("使用 Queryable 进行查询 :"); -// var phones = new List {"1921682012", "1921682013", "1921682014"}; -// var ssss = corpInfoRepository.Queryable().Where(x => x.Phones.Any(x => phones.Contains(x))); -// var r2 = ssss.ToList(); -// Console.WriteLine(r2); -// Console.WriteLine(); -// -// var dys = corpInfoRepository.Queryable().Select(x => new A {Name = x.Name}); -// var r = dys.ToList(); -// Console.WriteLine(r); -// Console.WriteLine(); -// -// -// Console.WriteLine("使用 Queryable 进行查询 个别字段:"); -// var dys2 = corpInfoRepository.Queryable().Where(x => x.Id > 0).Select(x => new {x.Id, x.Creator}) -// .FirstOrDefault(); -// Console.WriteLine(dys2.ToJson()); -// Console.WriteLine(); -// -// //使用 Queryable 进行查询 -// var corpSun1 = corpInfoRepository.Queryable().FirstOrDefault(x => x.No == "sun1"); -// var corpSun2 = corpInfoRepository.Queryable().FirstOrDefault(x => x.No == "sun2"); -// Console.WriteLine("使用 Queryable 进行查询:"); -// Console.WriteLine(corpSun2.ToJson()); -// -// -// //WhereIF -// var corpSunpNoRefix = "sun"; -// var corpSuns = corpInfoRepository -// .Queryable() -// .Where(x => x.Id > 0) -// //corpSunpNoRefix.IsNotEmpty()==true 时,才会带上后面的查询添加 -// .WhereIF(corpSunpNoRefix.IsNotEmpty(), x => x.No.Contains(corpSunpNoRefix)) -// .ToList(); -// Console.WriteLine("WhereIF:"); -// Console.WriteLine(corpSuns.ToJson()); -// -// //Queryable 分页查询 带 total -// var paginationResult1 = corpInfoRepository.Queryable() -// .Where(x => x.No.Contains(corpSunpNoRefix)) -// .Pagination(1, 5, out int total); -// -// Console.WriteLine("Queryable 分页查询 带 total:"); -// Console.WriteLine(total); -// Console.WriteLine(paginationResult1.ToJson()); -// -// //Queryable 分页查询 不带 total -// var paginationResult2 = corpInfoRepository.Queryable() -// .Where(x => x.No.Contains(corpSunpNoRefix)) -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// Console.WriteLine("Queryable 分页查询 不带 total:"); -// Console.WriteLine(paginationResult2.ToJson()); -// -// -// //动态字段查询 -// var queryResult1 = corpInfoRepository.Queryable() -// .Where(x => (string) x.Tags["string"] == "string") -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// var queryResult2 = corpInfoRepository.Queryable() -// .Where(x => (DateTime) x.Tags["datetime"] < DateTime.Now) -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// Console.WriteLine("动态字段查询:"); -// Console.WriteLine(queryResult1.ToJson()); -// Console.WriteLine(queryResult2.ToJson()); -// -// //更新下 方便下面left join 查看效果 -// corpInfoRepository.UpdateOne(x => new CorpInfo {No = "sun1"}, x => x.No == "sun11"); -// -// #endregion -// -// #region 更新 -// -// //更新符合条件的第一条数据 更新整个对象 -// corpSun1.Phones.Add("我是新增的"); -// var updateOneResult = corpInfoRepository.UpdateOne(corpSun1, x => x.No == "sun10"); -// Console.WriteLine("更新整个对象:"); -// Console.WriteLine(updateOneResult.ToJson()); -// -// var fieldList = Builders.Update.AddToSet("ids", 220827615942565900); -// FilterDefinition filter = Builders.Filter.Eq("No", "sun2"); -// corpInfoRepository.UpdateOne(filter, fieldList); -// -// corpInfoRepository.UpdateOne(x => new CorpInfo -// { -// Ids = x.Ids.AddToSet((long) 220827615942565900) -// }, x => x.No.StartsWith("sun2")); -// -// -// corpInfoRepository.UpdateOne(x => new CorpInfo -// { -// Phones = x.Phones.AddToSet("sss ' ,\" \\ \\\\ $ @@@ ") -// }, x => x.No.StartsWith("sun2")); -// corpInfoRepository.UpdateOne(x => new CorpInfo -// { -// Phones = x.Phones.AddToSet(new List {"sss", "22222"}) -// }, x => x.No.StartsWith("sun2")); -// -// var sss = corpInfoRepository.UpdateOne(x => new CorpInfo -// { -// //Id = corpSun1.Id, -// CreateDate = DateTime.MinValue, -// Phones = corpSun1.Phones.AddToSet("AddToSet"), -// AddressInfos = corpSun1.AddressInfos.AddToSet(new CorpAddressInfo {Id = 0, Address = "AddToSet"}) -// }, x => x.No.StartsWith("sun2")); -// -// //更新 自定义字段 实体键_id不允许更新 -// corpSun1.Phones.Add("我是新增的222222222222222222"); -// corpSun1.AddressInfos.Add(new CorpAddressInfo {Address = "新增的3"}); -// var updateOneResult2 = corpInfoRepository.UpdateOne(x => new CorpInfo -// { -// //Id = corpSun1.Id, -// CreateDate = DateTime.MinValue, -// Phones = corpSun1.Phones, -// AddressInfos = corpSun1.AddressInfos -// }, x => x.No.StartsWith("sun2")); -// Console.WriteLine("更新 自定义字段:"); -// Console.WriteLine(updateOneResult2.ToJson()); -// -// //更新多个 更新整个对象 -// corpSun1.Phones.Add("UpdateMany 更新整个对象"); -// var updateOneResult3 = corpInfoRepository.UpdateMany(corpSun1, x => x.No == "sun1"); -// Console.WriteLine("更新多个 更新整个对象:"); -// Console.WriteLine(updateOneResult3.ToJson()); -// -// //更新多个 更新整个对象 自定义字段 -// corpSun1.Phones.Add("UpdateMany 自定义字段"); -// var updateOneResult4 = corpInfoRepository.UpdateMany(x => new CorpInfo -// { -// Phones = corpSun1.Phones, -// }, x => x.No.StartsWith("sun")); -// Console.WriteLine("更新多个 自定义字段 :"); -// Console.WriteLine(updateOneResult4.ToJson()); -// -// #endregion -// -// -// #region 删除 -// -// //根据条件删除 一个 -// var deleteResult = corpInfoRepository.DeleteOne(x => x.No == "sun1"); -// Console.WriteLine("根据条件删除 一个:"); -// Console.WriteLine(deleteResult.ToJson()); -// -// //根据条件删除 多个 -// var deleteResult2 = corpInfoRepository.DeleteMany(x => x.No.StartsWith("sun1")); -// Console.WriteLine("根据条件删除 多个:"); -// Console.WriteLine(deleteResult2.ToJson()); -// -// #endregion -// -// //清空 测试数据清空下,一般清空是不要用到这个方法 -// corpInfoRepository.DeleteMany(x => x.Id > 0); -// //清空 测试数据清空下,一般清空是不要用到这个方法 -// //corpInfoRepository.CurrMongoDbContext.ClearCollection(); -// } -// -// /// -// /// 测试Provider -// /// -// /// -// static void TestMongonDbProvider() -// { -// //Console.WriteLine(1.GetHashCode()); -// //Console.WriteLine(1.GetHashCode()); -// //Console.WriteLine(1.GetHashCode()); -// -// //Console.WriteLine(2.GetHashCode()); -// //Console.WriteLine(2.GetHashCode()); -// //Console.WriteLine(2.GetHashCode()); -// -// //创建provider -// var testMongonDbProvider = new TestMongoDbProvider(new List {TestDbConfig}); -// //BPATestMongoDbContext 必须要继承 BPAMongoDbContext -// var testDbContext = testMongonDbProvider.GetDbContext(corpId); -// -// //根据企业ID构建文档集名称 -// var corpInfoCollectionName = testDbContext.BuildCollectionName(corpId); -// Console.WriteLine(corpInfoCollectionName); -// -// -// //获取文档集操作接口对象, -// var corpInfoCollection = testMongonDbProvider.GetCollection(corpId); -// -// //清空 测试数据清空下,一般清空是不要用到这个方法 -// testDbContext.ClearCollection(); -// -// #region 插入 -// -// //插入单个 -// corpInfoCollection.InsertOne(new CorpInfo -// { -// Id = BPAUniqueIdBulder.NextLong(), -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = "太阳国1", -// No = "sun1", -// Tags = new Dictionary -// { -// {"string", null}, -// {"int", null}, -// {"double", null}, -// {"datetime", null}, -// {"bool", null}, -// }, -// Phones = new List {"1921682012", "1921682012", "1921682012"} -// }); -// corpInfoCollection.InsertOne(new CorpInfo -// { -// Id = BPAUniqueIdBulder.NextLong(), -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = "太阳国2", -// No = "sun2", -// Tags = new Dictionary -// { -// {"string", "string"}, -// {"int", 10}, -// {"double", 20.00}, -// {"datetime", DateTime.Now}, -// {"bool", true}, -// } -// }); -// -// var insertCorpInfos = new List(); -// for (var i = 3; i < 10; i++) -// { -// insertCorpInfos.Add(new CorpInfo -// { -// Id = BPAUniqueIdBulder.NextLong(), -// AddressInfos = new List -// { -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", -// Remark = "二号办公地点" -// }, -// }, -// Creator = new CorpAddressInfo -// { -// Id = (long) DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", -// Remark = "一号办公地点" -// }, -// Name = $"太阳国{i}", -// No = $"sun{i}", -// Tags = new Dictionary -// { -// {"string", $"string{i}"}, -// {"int", 10 + i}, -// {"double", 20.00 + 1}, -// {"datetime", DateTime.Now.AddMinutes(i)}, -// {"bool", i % 2}, -// } -// }); -// } -// -// //批量插入 -// corpInfoCollection.InsertMany(insertCorpInfos); -// -// #endregion -// -// #region 查询 Queryable 强烈推荐使用 -// -// //使用 Queryable 进行查询 -// -// var dys = corpInfoCollection.Queryable().Where(x => x.Id > 0).Select(x => new {x.Creator, x.Id}) -// .FirstOrDefault(); -// Console.WriteLine(dys.ToJson()); -// -// var corpSun1 = corpInfoCollection.Queryable().FirstOrDefault(x => x.No == "sun1"); -// var corpSun2 = corpInfoCollection.Queryable().FirstOrDefault(x => x.No == "sun2"); -// Console.WriteLine("使用 Queryable 进行查询:"); -// Console.WriteLine(corpSun2.ToJson()); -// -// -// //WhereIF -// var corpSunpNoRefix = "sun"; -// var corpSuns = corpInfoCollection -// .Queryable() -// //corpSunpNoRefix.IsNotEmpty()==true 时,才会带上后面的查询添加 -// .WhereIF(corpSunpNoRefix.IsNotEmpty(), x => x.No.Contains(corpSunpNoRefix)) -// .ToList(); -// Console.WriteLine("WhereIF:"); -// Console.WriteLine(corpSuns.ToJson()); -// -// //Queryable 分页查询 带 total -// var paginationResult1 = corpInfoCollection.Queryable() -// .Where(x => x.No.Contains(corpSunpNoRefix)) -// .Pagination(1, 5, out int total); -// -// Console.WriteLine("Queryable 分页查询 带 total:"); -// Console.WriteLine(total); -// Console.WriteLine(paginationResult1.ToJson()); -// -// //Queryable 分页查询 不带 total -// var paginationResult2 = corpInfoCollection.Queryable() -// .Where(x => x.No.Contains(corpSunpNoRefix)) -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// Console.WriteLine("Queryable 分页查询 不带 total:"); -// Console.WriteLine(paginationResult2.ToJson()); -// -// -// //动态字段查询 -// var queryResult1 = corpInfoCollection.Queryable() -// .Where(x => (string) x.Tags["string"] == "string") -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// var queryResult2 = corpInfoCollection.Queryable() -// .Where(x => (DateTime) x.Tags["datetime"] < DateTime.Now) -// .OrderBy(x => x.No) -// .Pagination(1, 5); -// Console.WriteLine("动态字段查询:"); -// Console.WriteLine(queryResult1.ToJson()); -// Console.WriteLine(queryResult2.ToJson()); -// -// //更新下 方便下面left join 查看效果 -// corpInfoCollection.UpdateOne(x => new CorpInfo {No = "sun1"}, x => x.No == "sun11"); -// -// // left join -// var quryable1 = corpInfoCollection.Queryable(); -// var quryable2 = corpInfoCollection.Queryable(); -// var quryable5 = corpInfoCollection.Queryable(); -// var quryable3 = from c1 in quryable1 -// //left join -// join c2 in quryable2 -// on c1.No equals c2.No into temp -// from tt in temp.DefaultIfEmpty() -// join c5 in quryable5 -// on c1.No equals c5.No into temp2 -// from tt2 in temp2.DefaultIfEmpty() -// where c1.No == "sun1" -// select new -// { -// C1Id = c1.Id, -// C1No = c1.No, -// //C2Id = tt.Id, -// //C2No = tt.No, -// //C3Id = tt2.Id, -// //C3No = tt2.No, -// //C2Id = tt == null ? ObjectId.Empty : tt.Id, -// //C2No = tt == null ? string.Empty : tt.No, -// //C3Id = tt2 == null ? ObjectId.Empty : tt2.Id, -// //C3No = tt2 == null ? string.Empty : tt2.No -// }; -// //var quryable3 = from c1 in quryable1 -// // //left join -// // join c2 in quryable2 on c1.No equals c2.No into temp -// // from tt in temp.DefaultIfEmpty() -// // select new { c1, tt }; -// //quryable3 = quryable3.Where(x => x.c1.No == "sun1"); -// //var quryable4 = quryable3.Select(x => new -// //{ -// // C1Id = x.c1.Id, -// // C1No = x.c1.No, -// // C2Id = x.tt == null ? ObjectId.Empty : x.tt.Id, -// // C2No = x.tt == null ? string.Empty : x.tt.No -// //}); -// quryable3 = quryable3.Where(x => x.C1No == "sun1"); -// -// Console.WriteLine(quryable3.ToString()); -// var leftJoinReuslt = quryable3.ToList(); -// Console.WriteLine("left join:"); -// Console.WriteLine(leftJoinReuslt.ToJson()); -// -// #endregion -// -// #region 更新 -// -// //更新符合条件的第一条数据 更新整个对象 -// corpSun1.Phones.Add("我是新增的"); -// var updateOneResult = corpInfoCollection.UpdateOne(corpSun1, x => x.No == "sun10"); -// Console.WriteLine("更新整个对象:"); -// Console.WriteLine(updateOneResult.ToJson()); -// -// //更新 自定义字段 实体键_id不允许更新 -// corpSun1.Phones.Add("我是新增的2"); -// corpSun1.AddressInfos.Each(it => it.Id = (long) DateTime.Now.Ticks); -// corpSun1.AddressInfos.Add(new CorpAddressInfo {Address = "新增的3"}); -// var updateOneResult2 = corpInfoCollection.UpdateOne(x => new CorpInfo -// { -// //Id = corpSun1.Id, -// CreateDate = DateTime.Now.AddDays(50), -// Phones = corpSun1.Phones, -// AddressInfos = corpSun1.AddressInfos -// }, x => x.No.StartsWith("sun2")); -// Console.WriteLine("更新 自定义字段:"); -// Console.WriteLine(updateOneResult2.ToJson()); -// -// //更新多个 更新整个对象 -// corpSun1.Phones.Add("UpdateMany 更新整个对象"); -// var updateOneResult3 = corpInfoCollection.UpdateMany(corpSun1, x => x.No == "sun1"); -// Console.WriteLine("更新多个 更新整个对象:"); -// Console.WriteLine(updateOneResult3.ToJson()); -// -// //更新多个 更新整个对象 自定义字段 -// corpSun1.Phones.Add("UpdateMany 自定义字段"); -// var updateOneResult4 = corpInfoCollection.UpdateMany(x => new CorpInfo -// { -// Phones = corpSun1.Phones, -// }, x => x.No == "sun1"); -// Console.WriteLine("更新多个 自定义字段 :"); -// Console.WriteLine(updateOneResult4.ToJson()); -// -// #endregion -// -// -// #region 删除 -// -// //根据条件删除 一个 -// var deleteResult = corpInfoCollection.DeleteOne(x => x.No == "sun1"); -// Console.WriteLine("根据条件删除 一个:"); -// Console.WriteLine(deleteResult.ToJson()); -// -// //根据条件删除 多个 -// var deleteResult2 = corpInfoCollection.DeleteMany(x => x.No.StartsWith("sun1")); -// Console.WriteLine("根据条件删除 多个:"); -// Console.WriteLine(deleteResult2.ToJson()); -// -// #endregion -// -// //清空 测试数据清空下,一般清空是不要用到这个方法 -// testDbContext.ClearCollection(); -// Console.ReadLine(); -// } -// } -// -// public class A -// { -// public string Name { set; get; } -// } -// } \ No newline at end of file +using BPA.Component.ApolloClient; +using BPA.Component.DbClientTester; +using BPA.Component.MongoClientTester.Models; +using BPA.Component.MongoClientTester.Repositorys; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace BPA.Component.MongoClientTester; + +internal class Program +{ + private static async Task Main(string[] args) + { + var builder = new ConfigurationBuilder(); + builder.AddEnvironmentVariables(); + IConfiguration configuration = builder.Build(); + configuration.AddApolloConfiguration(); + + var services = new ServiceCollection(); + services.AddApollo(); + services.AddLogging(configure => { configure.AddConsole(); }); + services.AddScoped(); + services.AddTransient(); + + var serviceProvider = services.BuildServiceProvider(); + var testDbClient = serviceProvider.GetService(); + if (testDbClient == null) return; + + var userRepository = serviceProvider.GetService(); + var tags = new Dictionary + { + {"datetime", DateTime.Now}, + {"array0-1", new object[] {1, true, 66.2D, Enums.Aaa, DateTime.Now, ""}}, + {"array00", null}, + {"array01", new List {"sss", "bbb"}}, + {"array02", new List {new[] {"1", "2"}, new[] {"3", "4"}}}, + {"array03", new List {new() {Address = "ss", Id = DateTime.Now.Ticks, Latitude = 1, Longitude = 2, Remark = ""}}}, + }; + await userRepository.AddAsync(new CorpInfo + { + DB = long.MaxValue, + AddressInfos = new List + { + new() {Id = DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", Remark = "一号办公地点"}, + new() {Id = DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府五街", Remark = "二号办公地点"}, + }, + Name = "太阳国1", + No = "sun1", + Creator = new CorpAddressInfo {Id = DateTime.Now.Ticks, Latitude = 66.52, Longitude = 451.63, Address = "天府大道天府三街", Remark = "一号办公地点"}, + Tags = tags, + Phones = new List {"1921682012", "1921682012", "1921682012"} + }); + } +} + +public enum Enums +{ + Aaa = 1, + Bbb = 2 +} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Properties/launchSettings.json b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Properties/launchSettings.json index 1b142ab..66439f9 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Properties/launchSettings.json +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Properties/launchSettings.json @@ -3,9 +3,10 @@ "BPA.Component.LogClientTester": { "commandName": "Project", "environmentVariables": { - "APOLLO_META_SERVER_URL": "http://192.168.0.147:7010", - "APOLLO_COMMON_NAMESPACE": "BPA.test.common", - "APP_NAME": "BPA.test" + "ASPNETCORE_ENVIRONMENT": "Development", + "APOLLO_META_SERVER_URL": "http://10.2.1.21:28080", + "APOLLO_COMMON_NAMESPACE": "Dev.Common", + "APP_NAME": "BPA-DEV" } } } diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/CorpInfoRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/CorpInfoRepository.cs index 26c4b13..dfb6e98 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/CorpInfoRepository.cs +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/CorpInfoRepository.cs @@ -1,12 +1,16 @@ using BPA.Component.MongoClient; +using BPA.Component.MongoClient.Repository; using BPA.Component.MongoClientTester.Models; namespace BPA.Component.MongoClientTester.Repositorys { - public class CorpInfoRepository : BaseMGRepository, ICorpInfoRepository + public class CorpInfoRepository : BaseMongoDbRepository, ICorpInfoRepository { - public CorpInfoRepository(TestMongoDbProvider mongoDbProvider) : base(mongoDbProvider) + public CorpInfoRepository(TestMongoDcClient mongoDbClient) : base(mongoDbClient) { + } + + } } \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/ICorpInfoRepository.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/ICorpInfoRepository.cs index 6398a70..e8e44ba 100644 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/ICorpInfoRepository.cs +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/Repositorys/ICorpInfoRepository.cs @@ -1,9 +1,10 @@ -using BPA.Component.MongoClient; +using BPA.Component.MongoClient.Repository; using BPA.Component.MongoClientTester.Models; namespace BPA.Component.MongoClientTester.Repositorys { - public interface ICorpInfoRepository : IMGRepository + public interface ICorpInfoRepository : IBaseMongoDbRepository { + Task AddAsync(TDocument document) where TDocument : class, new(); } } diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestConfig.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestConfig.cs new file mode 100644 index 0000000..f4bd59c --- /dev/null +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestConfig.cs @@ -0,0 +1,20 @@ +using BPA.Component.ApolloClient; +using BPA.Component.MongoClient; +using Com.Ctrip.Framework.Apollo; +using Microsoft.Extensions.Configuration; + +namespace BPA.Component.DbClientTester; + +/// +/// test项目配置 +/// +public class TestConfig : ApolloBPAConfig +{ + [AutoWrite] + public MongoConfig MongoDbForWebApi1Db { get; set; } + + public TestConfig(ApolloConfigurationManager apolloConfigurationManager, IConfiguration configuration) : base(apolloConfigurationManager, configuration) + { + + } +} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDbProvider.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDbProvider.cs deleted file mode 100644 index c712b38..0000000 --- a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDbProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -using BPA.Component.MongoClient; - -namespace BPA.Component.MongoClientTester -{ - /// - /// 测试数据库 TestMongoDbProvider - /// - public class TestMongoDbProvider : MongoDbProvider - { - public TestMongoDbProvider(List mongoDbConfigs) : base(mongoDbConfigs) - { - } - - /// - /// 根据企业ID获取数据库别名 - /// - /// - /// - protected override string GetDbAliasByCropId(long corpId) - { - return "test-01"; - } - } -} \ No newline at end of file diff --git a/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDcClient.cs b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDcClient.cs new file mode 100644 index 0000000..8479224 --- /dev/null +++ b/src/BPA.Component.MongoClient/BPA.Component.MongoClientTester/TestMongoDcClient.cs @@ -0,0 +1,13 @@ +using BPA.Component.DbClientTester; +using BPA.Component.MongoClient; +using Microsoft.Extensions.Logging; + +namespace BPA.Component.MongoClientTester; + +public class TestMongoDcClient : BaseMongoDbClient +{ + public TestMongoDcClient(TestConfig config, ILogger logger = null) + : base(BuildMongoConfig(config.MongoDbForWebApi1Db.ConnectionString, config.MongoDbForWebApi1Db.DatabasesName), logger) + { + } +} \ No newline at end of file