SquirrelFramework.MongoDB 2.0.0

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

// Install SquirrelFramework.MongoDB as a Cake Tool
#tool nuget:?package=SquirrelFramework.MongoDB&version=2.0.0

SquirrelFramework.MongoDB 2.0.0

Squirrel Framework - A lightweight back-end framework and utilities kit based on MongoDB.

The word Squirrel has the meaning of squirrels and storage. The Squirrel Framework is working to make your MongoDB / Azure Cosmos DB-based applications lightweight and fast.

Dependencies Description

Release notes: 2.0.0 (Chinese, 中文)

Release notes: 1.0.15 (Chinese, 中文)

Release notes: 1.0.14 (Chinese, 中文)

Quick Start (Chinese, 中文)

Get Package

You can get the latest stable release from the official Nuget.org feed

https://www.nuget.org/packages/SquirrelFramework.MongoDB

Getting Started

  1. Create a .NET project, please ensure that the target framework MUST be .NET 6 or later

  2. Get the Nuget package by searching the keyword "SquirrelFramework.MongoDB" or using the Project Manager

    Install-Package SquirrelFramework.MongoDB -Version 2.0.0
    
  3. Create your Domain Model

    using SquirrelFramework.Domain.Model;
    
    [Database("YourDatabaseName")]
    [Collection("UsersCollectionName")]
    public class User : DomainModel
    {
        public string Name { get; set; }
        public string Gender { get; set; }
        public int Age { get; set; }
    }
    

    The [Database] attribute is not necessary, you can set the default MongoDB database name when initialing the configurations.

    Configurations.Configure("mongodb://localhost:27017", "Test");
    MongoDBBasicTestCrudRepository = new MongoDBBasicTestCrudRepository();
    var pingResult = MongoDBBasicTestCrudRepository.Ping();
    Console.WriteLine(pingResult);
    

    Since 1.0.14 the [Collection] attribute is no longer required. If you not specified the [Collection] attribute, the Squirrel Framework use the class name as the collection name.

  4. Create your Repository for MongoDB CRUD

    using SquirrelFramework.Repository;
    
    public class UserRepository: RepositoryBase<User> {}
    
  5. Now you are free to perform various operations on MongoDB, here are some examples

            var userRepo = new UserRepository();
    
    • Add a new user record

          userRepo.Add(new User{
              Name = "Hendry",
              Gender = "Male",
              Age = 18,
              Geolocation = new Geolocation(121.551949, 38.890957)
          });
      
    • Get all users who are 2 kilometers away from me

          userRepo.GetNearBy(new Geolocation(121.551949, 38.890957), 2000);
      
    • Bulk delete users who are older than 25 asynchronously

          userRepo.DeleteManyAsync(u => u.Age > 25);
      
    • Get the third page (15 records) of all user data and descending sort by the Age field

          //  Method signature
          //  public IEnumerable<TDomain> GetAllByPageSortBy(
          //      int pageIndex,
          //      int pageSize,
          //      Expression<Func<TDomain, object>> sortBy,
          //      bool isSortByDescending = false
          //  );
      
          userRepo.GetAllByPageSortBy(2, 15, u => u.Age, true);
      
  6. If your data collection is dynamic, for example you have multiple collections to store your user information:

    • Users201801
    • Users201802
    • Users201803
    • ...

    You can use the CustomizedRepositoryBase class as a base class

        public class UserRepository: CustomizedRepositoryBase<User> {}
    

    Then you can provide the specific collection name for each CRUD operation.

    • Add a new user record
          var userRepo = new UserRepository();
          userRepo.Add("Users201805", new User{
              Name = "George",
              Gender = "Male",
              Age = 18,
              Geolocation = new Geolocation(121.551949, 38.890957)
          });
      
  7. Create your Domain Service (This is not a necessary step)

        public class UserService : ServiceBase<User, UserRepository> {}
    

Contributing

  • George Qi me@nap7.com

If you have any questions, please feel free to contact me

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
2.0.0 140 5/27/2023
0.9.2 459 7/7/2020