VOOZH about

URL: https://www.nuget.org/packages/NetPro.MongoDb

⇱ NuGet Gallery | NetPro.MongoDb 6.0.16




👁 Image
NetPro.MongoDb 6.0.16

dotnet add package NetPro.MongoDb --version 6.0.16
 
 
NuGet\Install-Package NetPro.MongoDb -Version 6.0.16
 
 
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.16" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetPro.MongoDb" Version="6.0.16" />
 
Directory.Packages.props
<PackageReference Include="NetPro.MongoDb" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetPro.MongoDb --version 6.0.16
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.MongoDb, 6.0.16"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NetPro.MongoDb@6.0.16
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetPro.MongoDb&version=6.0.16
 
Install as a Cake Addin
#tool nuget:?package=NetPro.MongoDb&version=6.0.16
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp3.1 netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
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.16 412 7/24/2023
6.0.15 611 7/19/2022
6.0.14 616 7/10/2022
6.0.13 621 6/15/2022
6.0.12 616 6/15/2022
6.0.11 595 6/15/2022
6.0.10 612 6/11/2022
6.0.9 606 6/8/2022
6.0.8 643 5/26/2022
6.0.8-beta.3 302 5/24/2022
6.0.8-beta.2 283 5/24/2022
6.0.7 621 5/18/2022
6.0.6 621 4/28/2022
6.0.5-beta.20 270 4/27/2022
6.0.5-beta.19 312 4/25/2022
6.0.5-beta.18 272 4/22/2022
6.0.5-beta.17 277 4/16/2022
6.0.5-beta.16 356 4/8/2022
6.0.5-beta.15 276 4/8/2022
6.0.5-beta.14 286 4/7/2022
Loading failed