Chd.Library.NoSQL 9.0.5

dotnet add package Chd.Library.NoSQL --version 9.0.5                
NuGet\Install-Package Chd.Library.NoSQL -Version 9.0.5                
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="Chd.Library.NoSQL" Version="9.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chd.Library.NoSQL --version 9.0.5                
#r "nuget: Chd.Library.NoSQL, 9.0.5"                
#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.
// Install Chd.Library.NoSQL as a Cake Addin
#addin nuget:?package=Chd.Library.NoSQL&version=9.0.5

// Install Chd.Library.NoSQL as a Cake Tool
#tool nuget:?package=Chd.Library.NoSQL&version=9.0.5                

NoSql helper library for .Net Core

Chd (cleverly handle difficulty) library helps you cleverly handle difficulty, writing code fastly and do your application stable.

📝 Table of Contents

🧐 About

NoSql databases are a document databases with the scalability and flexibility that you want with the querying and indexing that you need.

🏁 Getting Started

NoSql databases use documents that can contain sub-documents in complex hierarchies making it expressive and flexible.

Prerequisites

You must use .net core 9.0 or higher

🎈 Usage

There are two ways to use the library. We can use ASP.NET Core Dependency Injection metodology or we can use library's own registiration method.

💉 First Way Injection NoSqlDB Helper Classes Into The Project

We inject IMongoDatabase to IServiceCollection in Program.cs. We can use IMongoDatabase in our controller classes or service classes.

   var builder = WebApplication.CreateBuilder(args);
   ....
   ....
   builder.Services.AddNoSQL(ServerType.MongoDB);
💠 Manage Data Using Asp.Net Core Dependency Injection On Controller Class

We injected IMongoDatabase to IServiceCollection in Program.cs. We can use IMongoDatabase in our controller classes. We insert data to MongoDB with the code below. You can use this code in your controller or service classes. We use DataContainer class for inserting data to MongoDB. You can use your own class for inserting data to MongoDB.

    public class MongoDBTestController : Controller
    {
        public IMongoDatabase Database { get; }
        public MongoDBTestController(IMongoDatabase database)
        {
            Database = database;
        }
        [Route("InsertDataToMongoDB")]
        [HttpGet]
        public string? InsertDataToMongoDB()//For testing on swagger or etc..
        {
            Database.GetCollection<DataContainer>("testCollection").InsertOne(new DataContainer { Id = 3, Name = "Mehmet" });
            return "Ok";
        }
    }

    class DataContainer
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
💠 Apsettings Configurations

You must add code below in appsettings.json

"NoSQL": {
    "Host": "192.168.1.5", // change host
    "UserName": "mongoadmin",// change username
    "Password": "adminxxxx",// change password
    "Port": "6005",// change port
    "Database": "TestDatabase" // change database name
  } 

Run application and go to swagger. You can see the InsertDataToMongoDB method on swagger. You can test the method on swagger.

💡 Second Way Register NoSqlDB Using Library's Own Method

In this way, you register MongoDB using RegisterMongoServer method only once in project life cycle.

 private static void RegisterMongoDB()
 {
     var mongoConnectionString = ConnectionStringHelper.BuildMongoDBConnectionString("mongoadmin", "chd_library_admin", "TestDatabase", 6005);
     ConnectionManager.RegisterMongoServer(mongoConnectionString);
 }
💠 Manage Data Any Where In The Project Not Only Injectable Classes

After registering MongoDB using RegisterMongoServer method, we can manage and view data in MongoDB any where in the project.

 public static void InsertDataToMongoDB()
 {
     ConnectionManager.GetTable<DataContainer>().InsertOne(new DataContainer { Id = 3, Name = "Mehmet" });
 }

📑 Test Result

After running the method, you can see the data on MongoDB Compass or Robo 3T.

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

Thank you for using my library.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
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
9.0.5 64 1/30/2025
9.0.4 100 1/1/2025
9.0.3 89 12/29/2024
9.0.2 77 12/29/2024
9.0.1 84 12/29/2024
9.0.0 102 12/25/2024
8.0.7 89 12/23/2024
8.0.6 88 12/23/2024
7.2.8 547 8/9/2023
1.2.8 632 5/3/2023