MongoSharper 1.0.25

dotnet add package MongoSharper --version 1.0.25
                    
NuGet\Install-Package MongoSharper -Version 1.0.25
                    
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="MongoSharper" Version="1.0.25" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MongoSharper" Version="1.0.25" />
                    
Directory.Packages.props
<PackageReference Include="MongoSharper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MongoSharper --version 1.0.25
                    
#r "nuget: MongoSharper, 1.0.25"
                    
#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.
#:package MongoSharper@1.0.25
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MongoSharper&version=1.0.25
                    
Install as a Cake Addin
#tool nuget:?package=MongoSharper&version=1.0.25
                    
Install as a Cake Tool

MongoSharper

MongoSharper is a lightweight C# library designed to simplify standard CRUD operations and integrate seamlessly with MongoDB, including support for advanced features like Atlas Search.


🚀 Features

  • Easy-to-use, strongly typed repository pattern
  • Standard CRUD operations
  • Support for MongoDB Atlas Search
  • Flexible filtering and projection
  • Index creation utility
  • AutoDelete of documents (Time to live feature)

📦 Installation

You can install the MongoSharper package via NuGet:

Install-Package MongoSharper

🧑‍💻 Usage

1. Define Your Model

Your model should inherit from DocumentBase:

public class MyClass : DocumentBase
{
    public string MyProperty1 { get; set; }
}

2. Instantiate the Repository

Replace TEntity with your model class when using the generic repository:

var mongoRepo = new MongoNetRepo<MyClass>("your_connection_string", "your_database_name");

3. Use the Available Methods

You can now call any of the supported methods on the mongoRepo instance.


🛠️ Supported Methods

CRUD Operations

  • void Create(TEntity document)
    Inserts a new document.

  • Task<TEntity> Replace(string id, TEntity newDocument)
    Replaces an existing document.

  • Task<bool> Delete(string id)
    Deletes a document by ID.

  • Task<TEntity> Get(Expression<Func<TEntity, bool>> filterExpression)
    Retrieves a document by filter.

  • Task<TEntity> GetById(string id)
    Retrieves a document by ID.

  • Task<IEnumerable<TEntity>> Get()
    Retrieves all documents.

  • Task<IEnumerable<TEntity>> GetTop(int limit)
    Retrieves the top N documents.

Filtering & Projection

  • IEnumerable<TProjected> FilterBy<TProjected>(Expression<Func<TEntity, bool>> filterExpression, Expression<Func<TEntity, TProjected>> projectionExpression)
    Filters and projects data.

  • Task<IEnumerable<TEntity>> FilterBy(Expression<Func<TEntity, bool>> filterExpression)
    Filters data by criteria.

  • IQueryable<TEntity> GetAsQueryable()
    Gets a queryable collection.

Search Operations

  • IEnumerable<TEntity> GetTextSearchResults(string index, string searchField, string searchText)
    Performs full-text search.

  • IEnumerable<TEntity> GetRegexSearchResults(string searchField, string regex, string index)
    Performs regex-based search.

Utility

  • void CreateIndex(TEntity entity, string fieldName, string indexName, bool unique = false)
    Creates an index on a field.

  • Task<bool> DeleteAllDocuments()
    Deletes all documents from the collection.

  • Task<bool> AutoDelete(TEntity entity, int value, TimeUnit timeUnit)
    Deletes expired documents from collection.


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.25 120 4/19/2025
1.0.24 101 4/19/2025
1.0.23 175 4/18/2025
1.0.22 166 4/2/2025
1.0.21 176 4/2/2025