NetPro.MongoDb 6.0.15

.NET 6.0 .NET Core 3.1
dotnet add package NetPro.MongoDb --version 6.0.15
NuGet\Install-Package NetPro.MongoDb -Version 6.0.15
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetPro.MongoDb" Version="6.0.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.MongoDb --version 6.0.15
#r "nuget: NetPro.MongoDb, 6.0.15"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetPro.MongoDb as a Cake Addin
#addin nuget:?package=NetPro.MongoDb&version=6.0.15

// Install NetPro.MongoDb as a Cake Tool
#tool nuget:?package=NetPro.MongoDb&version=6.0.15

Mongodb使用

NuGet

对Mongodb的封装,简化使用,支持多库

使用

appsetting.json
"MongoDbOption": {
    "ConnectionString": [
      {
        "Key": "mongo1", //连接串key别名,唯一
        "Value": "mongodb://192.168.100.187:27017/netprodemo" //别名key对应的连接串
      },
      {
        "Key": "mongo2", //连接串key别名,唯一
        "Value": "mongodb://192.168.100.187:27017/netprodemo2" //别名key对应的连接串
      }
    ]
  },

启用服务

没有基于NetPro.Web.Api 的使用场景,必须手动进行初始化,如下:

IConfiguration Configuration;

public void ConfigureServices(IServiceCollection services)
{
      //MongoDb 连接配置文件
       services.AddMongoDb(Configuration);
}

基于NetPro.Web.Api的使用,只需要添加引用后配置以上appsetting.josn配置MongoDbOption节点即可

当想自定义连接字符串获取方式时,无论是否基于NetPro.Web.Api, 都能通过传入委托来自定义连接字符串获取方式:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMongoDb(GetConnectionString);
}

public IList<ConnectionString> GetConnectionString(IServiceProvider serviceProvider)
{
    var connector = new List<ConnectionString>();
    connector.Add(new ConnectionString { Key = "2", Value = "mongodb://192.168.100.187:27017/netprodemo2" });
    return connector;
}

使用说明

entity 实体示例

 [CollectionName("hu")]
    public class Product : Document
    {
        //[BsonId]
        //[BsonRepresentation(BsonType.ObjectId)]
        //public string Id { get; set; }

        [BsonElement("Name")]
        public string Name { get; set; }
        public string Category { get; set; }
        public string Summary { get; set; }
        public string Description { get; set; }
        public string ImageFile { get; set; }
        public int Price { get; set; }
    }
 public class MongoDBService : IMongoDBService
    {
        private readonly IMongoDBMulti _mongoDBMulti;
        public MongoDBService(IMongoDBMulti mongoDBMulti)
        {
            _mongoDBMulti = mongoDBMulti;
        }

        /// <summary>
        /// 查询
        /// </summary>
        public Product Find(string key = "mongo1")
        {
            var mongodb = _mongoDBMulti[key];
            var filter = Builders<BsonDocument>.Filter;
            var product = mongodb.GetCollection<Product>().Find(s => s.Category == "").FirstOrDefault();

            return product;
        }
    }
更新中...
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.15 239 7/19/2022
6.0.14 258 7/10/2022
6.0.13 244 6/15/2022
6.0.12 235 6/15/2022
6.0.11 225 6/15/2022
6.0.10 229 6/11/2022
6.0.9 243 6/8/2022
6.0.8 263 5/26/2022
6.0.8-beta.3 102 5/24/2022
6.0.8-beta.2 74 5/24/2022
6.0.7 236 5/18/2022
6.0.6 252 4/28/2022
6.0.5 282 3/30/2022
6.0.5-beta.20 66 4/27/2022
6.0.5-beta.19 69 4/25/2022
6.0.5-beta.18 66 4/22/2022
6.0.5-beta.17 67 4/16/2022
6.0.5-beta.16 140 4/8/2022
6.0.5-beta.15 71 4/8/2022
6.0.5-beta.14 85 4/7/2022
6.0.5-beta.13 77 4/7/2022
6.0.5-beta.12 76 4/6/2022
6.0.5-beta.11 90 4/6/2022
6.0.5-beta.10 87 3/31/2022
6.0.5-beta.9 77 3/26/2022
6.0.5-beta.8 94 3/22/2022
6.0.5-beta.7 78 3/21/2022
6.0.5-beta.6 79 3/14/2022
6.0.5-beta.5 78 3/2/2022
6.0.5-beta.4 83 2/22/2022
6.0.5-beta.3 84 2/18/2022
6.0.5-beta.2 70 2/18/2022
6.0.5-beta.1 81 2/16/2022
6.0.4 287 2/10/2022
6.0.3 279 2/9/2022
6.0.3-beta.9 70 2/10/2022
6.0.3-beta.7 98 1/27/2022
6.0.3-beta.6 95 1/19/2022
6.0.3-beta.5 87 1/17/2022
6.0.3-beta.4 98 1/16/2022
6.0.3-beta.3 95 1/14/2022
6.0.3-beta.2 86 1/13/2022
6.0.3-beta.1 101 1/11/2022
6.0.2 188 1/6/2022
6.0.1 807 12/3/2021
3.1.10 296 7/29/2021
3.1.9 233 7/1/2021
3.1.8 281 12/15/2020
3.1.6 2,348 9/16/2020
3.1.1 1,523 6/23/2020
3.1.0 3,529 5/24/2020
1.0.1 1,617 5/4/2020
1.0.0 1,547 4/27/2020