Maniceraf.SimpleCoreMongoDbHelper
1.0.0
See the version list below for details.
dotnet add package Maniceraf.SimpleCoreMongoDbHelper --version 1.0.0
NuGet\Install-Package Maniceraf.SimpleCoreMongoDbHelper -Version 1.0.0
<PackageReference Include="Maniceraf.SimpleCoreMongoDbHelper" Version="1.0.0" />
paket add Maniceraf.SimpleCoreMongoDbHelper --version 1.0.0
#r "nuget: Maniceraf.SimpleCoreMongoDbHelper, 1.0.0"
// Install Maniceraf.SimpleCoreMongoDbHelper as a Cake Addin #addin nuget:?package=Maniceraf.SimpleCoreMongoDbHelper&version=1.0.0 // Install Maniceraf.SimpleCoreMongoDbHelper as a Cake Tool #tool nuget:?package=Maniceraf.SimpleCoreMongoDbHelper&version=1.0.0
Maniceraf.SimpleCoreMongoDbHelper
Maniceraf.SimpleCoreMongoDbHelper is a .NET Core-based class library created to simplify MongoDB operations within your application framework. This library provides fundamental implementations for common MongoDB database tasks.
Installation
To install Maniceraf.SimpleCoreMongoDbHelper, you can use NuGet Package Manager:
NuGet\Install-Package Maniceraf.SimpleCoreMongoDbHelper -Version 1.0.0
Usage
Initialization
To start using the Maniceraf.SimpleMongoDbHelper in your project, initialize an instance of the FastMongoDbHelperclass:
// Initialize the FastMongoDbHelper
var mongoDbHelper = new FastMongoDbHelper("connectionString", "databaseName");
// Create a WeatherForecast model class
public class WeatherForecast
{
[BsonId]
public ObjectId Id { get; set; }
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
Basic Operations
The library supports basic MongoDB operations such as:
1. Get all databases in the Client:
// Get all databases with synchronous
var all = mongoDbHelper.GetAllDatabases();
// Get all databases with asynchronous
var all = await mongoDbHelper.GetAllDatabasesAsync();
2. Get all documents in collection <T>:
// Get all with synchronous
var items = mongoDbHelper.GetAll<WeatherForecast>();
// Get all with asynchronous
var items = await mongoDbHelper.GetAllAsync<WeatherForecast>();
3. Get a document by Id in collection <T>:
// Get a document by Id with synchronous
var item = mongoDbHelper.GetById<WeatherForecast>("65699649600d064a2924c5d9");
// Get a document by Id with asynchronous
var item = await mongoDbHelper.GetByIdAsync<WeatherForecast>("65699649600d064a2924c5d9");
4. Insert a document into collection <T>:
// Create entity
var model = new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.UtcNow.Date),
Summary = "Sunny",
TemperatureC = 32,
};
// Insert a document with synchronous
mongoDbHelper.Insert<WeatherForecast>(model);
// Insert a document with asynchronous
await mongoDbHelper.InsertAsync<WeatherForecast>(model);
5. Insert multiple documents into collection <T>:
// Create a entity list
var model = new List<WeatherForecast>
{
new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.UtcNow.Date),
Summary = "Sunny",
TemperatureC = 32,
},
new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.UtcNow.Date),
Summary = "Sunny",
TemperatureC = 32,
}
};
// Insert multiple documents with synchronous
mongoDbHelper.InsertMany<WeatherForecast>(model);
// Insert multiple documents with asynchronous
await mongoDbHelper.InsertManyAsync<WeatherForecast>(model);
Contributing
Contributions are welcome! Feel free to raise issues or submit pull requests.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- MongoDB.Driver (>= 2.22.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.