Chd.Library.NoSQL
9.0.4
See the version list below for details.
dotnet add package Chd.Library.NoSQL --version 9.0.4
NuGet\Install-Package Chd.Library.NoSQL -Version 9.0.4
<PackageReference Include="Chd.Library.NoSQL" Version="9.0.4" />
paket add Chd.Library.NoSQL --version 9.0.4
#r "nuget: Chd.Library.NoSQL, 9.0.4"
// Install Chd.Library.NoSQL as a Cake Addin #addin nuget:?package=Chd.Library.NoSQL&version=9.0.4 // Install Chd.Library.NoSQL as a Cake Tool #tool nuget:?package=Chd.Library.NoSQL&version=9.0.4
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
- Mehmet Yoldaş - Linkedin
See also the list of contributors who participated in this project.
🎉 Acknowledgements
Thank you for using my library.
Product | Versions 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. |
-
net9.0
- Chd.Library.Common (>= 9.0.7)
- MongoDB.Driver (>= 2.20.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.