![]() |
VOOZH | about |
dotnet add package SquirrelFramework.MongoDB --version 2.0.0
NuGet\Install-Package SquirrelFramework.MongoDB -Version 2.0.0
<PackageReference Include="SquirrelFramework.MongoDB" Version="2.0.0" />
<PackageVersion Include="SquirrelFramework.MongoDB" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="SquirrelFramework.MongoDB" />Project file
paket add SquirrelFramework.MongoDB --version 2.0.0
#r "nuget: SquirrelFramework.MongoDB, 2.0.0"
#:package SquirrelFramework.MongoDB@2.0.0
#addin nuget:?package=SquirrelFramework.MongoDB&version=2.0.0Install as a Cake Addin
#tool nuget:?package=SquirrelFramework.MongoDB&version=2.0.0Install as a Cake Tool
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.
Release notes: 2.0.0 (Chinese, 中文)
Release notes: 1.0.15 (Chinese, 中文)
Release notes: 1.0.14 (Chinese, 中文)
You can get the latest stable release from the official Nuget.org feed
https://www.nuget.org/packages/SquirrelFramework.MongoDB
Create a .NET project, please ensure that the target framework MUST be .NET 6 or later
Get the Nuget package by searching the keyword "SquirrelFramework.MongoDB" or using the Project Manager
Install-Package SquirrelFramework.MongoDB -Version 2.0.0
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.
Create your Repository for MongoDB CRUD
using SquirrelFramework.Repository;
public class UserRepository: RepositoryBase<User> {}
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);
If your data collection is dynamic, for example you have multiple collections to store your user information:
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.
var userRepo = new UserRepository();
userRepo.Add("Users201805", new User{
Name = "George",
Gender = "Male",
Age = 18,
Geolocation = new Geolocation(121.551949, 38.890957)
});
Create your Domain Service (This is not a necessary step)
public class UserService : ServiceBase<User, UserRepository> {}
If you have any questions, please feel free to contact me
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.