Maniceraf.SimpleCoreMongoDbHelper 1.0.0

There is a newer version of this package available.
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                
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="Maniceraf.SimpleCoreMongoDbHelper" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Maniceraf.SimpleCoreMongoDbHelper --version 1.0.0                
#r "nuget: Maniceraf.SimpleCoreMongoDbHelper, 1.0.0"                
#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 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 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. 
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
1.0.1 237 12/1/2023
1.0.0 121 12/1/2023