MongoHead 0.5.2

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

// Install MongoHead as a Cake Tool
#tool nuget:?package=MongoHead&version=0.5.2

MongoHead

Provides the layer for MongoDB operations over .NET driver 2.15.0. Also MongoHead includes a BaseData and BaseEntity class to speed up your application development process. MongoHead is a .NET 6.0 Library

Installation

Available on NuGet: https://www.nuget.org/packages/MongoHead/

Dependencies

Here is the list of installed NuGet packages and versions

  1. MongoDB.Driver (v2.15.0)
  2. Microsoft.Extensions.Options (v6.0.0)
  3. Microsoft.Extensions.Configuration (v6.0.1)

Classes

MongoDBHelper

Helper for mongodb operations. Provides CRUD operations. Needs MongoDBConfig instance to configure connection to Db and and a Type to operate with it. Type names are equal to the collection names in MongoHead ecosystem.

📢 We assume that your entity (type) has inherited BaseEntity and these some properties by defalt. Please check BaseEntity class

MongoDBConfig

Simple class used to transfer database connection parameters to our MongoDBhelper class These parameters are "ConnectionString" and "DatabaseName"

Filter and ExpressionBuilder

Filter used in MongoDBHelper and BaseData class to define query parameters and ExpressionBuilder is used as a helper class to convert filter object to linq expressions

BaseData

An implementation of IBaseData and aims to provide base CRUD methods to your data layer classes

BaseEntity Classes (BaseEntitySimple, BaseEntityLight, BaseEntity, BaseEntityComplex)

Each class adds some fields to entity provide to support to eliminating unnecessary properties on your entities and keeps your database collections lighter. Latest base entity hierarchy (inheritence) is: BaseEntitySimple < BaseEntityLight < BaseEntity < BaseEntityComplex

BaseEntitySimple adds this property
  • _id
BaseEntityLight adds this property
  • _DateUtcCreated
BaseEntity adds these properties
  • _DateUtcModified
  • _IsActive
BaseEntityComplex adds this property
  • _UserId

Sample Application

MongoHead Configuration

Add Mongo DB settings to you appsettings.json setting file

Sample JSON settings:

{
  "Settings": {
    "MongoDB": {
      "ConnectionString": "mongodb://localhost",
      "DatabaseName": "MongoHeadSample"
    } //MongoDB
  } //Settings
}

❗:exclamation::exclamation: Information given after this line is draft at the moment ❗:exclamation::exclamation:

Sample Application Organization

Our sample application is an ASP.NET Razor Pages application for .NET 6 Of course there may be lots of different achitectures. We are going to keep it simple and follow n-layered architecture. Different samples using different approaches are appreciated. 😃

Entities

You need entities to interact with mongodb collection. If you have an entity named X you are going a have collection with name X in your database. Your entity classes may inherit our "BaseEntity" class provided by MongoHead. With this inheritence all your class will have same base fiels in your database. To show a simple entity implementation, our sample application contains an entity named "Test". Sample entity may be found in "/Model" folder of the sample app.

Data Layers

Sample data layer may be found in "/Data" folder of the sample app.

Business Layers

Sample business layer may be found in "/Business" folder of the sample app.

ViewModels

Sample viewmodel may be found in "/ViewModels" folder of the sample app.

Pages/People

Wraps all elements with two pages: a list page (/pages/people/index) and a form page (/pages/people/form). List page has search and delete samples. Form page has add/update samples.

MongoDB

Setup and installation details can be obtained from official web site.

MongoDB Community Server Download

For setup please visit https://www.mongodb.com/download-center?jmp=nav#community

MongoDB Community Server Installation steps for Windows

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

AutoMapper

In our sample projects we prefer to use automapper to map our objects between presentation and data layer For more informtation: https://automapper.org/

References

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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
0.5.2 466 4/12/2022
0.5.1 403 3/14/2022
0.5.0 419 3/12/2022
0.4.0 500 4/30/2022
0.3.0 1,129 2/22/2019
0.2.0 1,162 10/26/2018
0.1.0 1,247 9/12/2018