meerkat 1.1.0
dotnet add package meerkat --version 1.1.0
NuGet\Install-Package meerkat -Version 1.1.0
<PackageReference Include="meerkat" Version="1.1.0" />
paket add meerkat --version 1.1.0
#r "nuget: meerkat, 1.1.0"
// Install meerkat as a Cake Addin #addin nuget:?package=meerkat&version=1.1.0 // Install meerkat as a Cake Tool #tool nuget:?package=meerkat&version=1.1.0
πΎ Meerkat
Meerkat is an ODM (Object Document Mapper) library designed to replicate the functionality of NodeJS's Mongoose in the .NET ecosystem. π For those unfamiliar, Mongoose is a JavaScript ODM wrapper library that simplifies data access when working with MongoDB. Similarly, Meerkat wraps around the official MongoDB client library for .NET, simplifying common data access patterns. It also adds support for the DateOnly
and TimeOnly
types introduced in .NET 6. π
β°
The name Meerkat is a playful homage to Mongoose, as a meerkat is a type of mongoose. π If you find this library cool or useful, don't forget to give it a βοΈ star!
π¨ Breaking Changes
With the release of version 1.1.0, the underlying MongoDB driver was upgraded to 3.1.0. This removes the IMongoQueryable<T>
interface returned by the Query<TSchema>()
method, replacing it with the built-in IQueryable<T>
interface. π
π€ Contributing
Thereβs still a lot to be done! Feel free to:
- Open new issues to suggest features or report bugs π
- Submit PRs with updates or improvements π οΈ
π¦ Installation
Manual Installation (for the hardcore devs πͺ)
Add the following to your .csproj
file:
<PackageReference Include="meerkat" Version="1.1.0"/>
Visual Studio Package Manager Console
Run the following command:
Install-Package meerkat
.NET CLI
Run the following in your terminal:
dotnet add package meerkat
π οΈ Setup
Before using any of Meerkat's functions, you need to initialize it. This only needs to be done once. π
using meerkat;
...
Meerkat.Connect("<any valid full MongoDB connection string>"); // e.g., mongodb://user:password@server-address:port/database-name?other-options
π Usage
Ensure youβve declared the necessary namespace at the top of your class file:
using meerkat;
Note: All async methods support CancellationToken
for canceling operations. β³
𧩠Modelling
All models must inherit from the abstract Schema
class. The Schema
class has a virtual
Id
property that can be overridden in your model. By default, the Id
is of type ObjectId
.
class Student : Schema
{
public override object Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Student()
{
// Example: Generate a random ID (you'd likely use a better method in production)
Id = (new Random()).Next();
}
}
To specify a custom collection name or enable timestamp tracking:
[Collection(Name = "Persons", TrackTimestamps = true)]
public class Student : Schema
{
...
}
πΎ Persistence
Meerkat simplifies CRUD operations by combining create and update into a single API. If an entity doesnβt exist, itβs inserted; if it does, itβs updated. π
var student = new Student
{
FirstName = "Olubakinde",
LastName = "Chukumerije"
};
await student.SaveAsync(); // or student.Save(); for synchronous calls
Itβs that simple! π
π Querying
Find by ID
var student = await Meerkat.FindByIdAsync<Student>(1234); // or Meerkat.FindById<Student>(1234); for sync calls
Find by Predicate
var student = await Meerkat.FindOneAsync<Student>(x => x.FirstName == "John"); // or Meerkat.FindOne(x => x.LastName == "Jane");
Complex Queries
For complex queries, you can access the underlying IQueryable
:
var queryable = Meerkat.Query<Student>();
var students = await queryable
.Where(x => x.FirstName == "Olubakinde")
.ToListAsync();
ποΈ Removal
Remove by ID
await Meerkat.RemoveByIdAsync<Student>(1234); // or Meerkat.RemoveById<Student>(1234); for sync calls
Remove by Predicate
await Meerkat.RemoveOneAsync<Student>(x => x.FirstName == "John"); // or Meerkat.RemoveOne(x => x.LastName == "Jane");
Remove All Matching Entities
await Meerkat.RemoveAsync<Student>(x => x.FirstName == "John"); // or Meerkat.Remove(x => x.LastName == "Jane");
β Existence Checks
Check if Any Entities Exist
var exists = await Meerkat.ExistsAsync<Student>(); // or Meerkat.Exists<Student>(); for sync calls
Check if Entities Match a Predicate
var exists = await Meerkat.ExistsAsync<Student>(x => x.FirstName.StartsWith("Ja")); // or Meerkat.Exists<Student>(x => x.FirstName.StartsWith("Ja"));
π’ Counting
Count All Entities
var count = await Meerkat.CountAsync<Student>(); // or Meerkat.Count<Student>(); for sync calls
Count Entities Matching a Predicate
var count = await Meerkat.CountAsync<Student>(x => x.FirstName.StartsWith("Ja")); // or Meerkat.Count<Student>(x => x.FirstName.StartsWith("Ja"));
π Collections
Meerkat allows for bulk upsert operations on collections of entities, both synchronously and asynchronously. π¦
var peter = new Student();
var paul = new Student();
var students = new [] { peter, paul };
await students.SaveAllAsync(); // or students.SaveAll(); for sync calls
Enjoy using Meerkat! π If you have any questions or feedback, feel free to reach out or contribute to the project. π
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- MongoDB.Driver (>= 3.1.0)
- mongo-url-parser (>= 1.1.0)
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.1.0 | 41 | 2/2/2025 |
1.0.19 | 35 | 2/2/2025 |
1.0.18 | 145 | 8/17/2024 |
1.0.17 | 274 | 11/5/2023 |
1.0.16 | 136 | 11/5/2023 |
1.0.13 | 4,963 | 6/8/2022 |
1.0.12 | 538 | 2/4/2022 |
1.0.11 | 450 | 2/4/2022 |
1.0.10 | 271 | 1/3/2022 |
1.0.9 | 367 | 10/27/2021 |
1.0.8 | 324 | 10/27/2021 |
1.0.7 | 329 | 10/26/2021 |
1.0.6 | 330 | 10/25/2021 |
1.0.5 | 312 | 10/23/2021 |
1.0.4 | 311 | 10/11/2021 |
1.0.3 | 338 | 10/8/2021 |
1.0.2 | 341 | 10/8/2021 |
1.0.1 | 323 | 10/7/2021 |
1.0.0 | 331 | 10/6/2021 |
1.0.0-beta.2 | 189 | 10/6/2021 |
1.0.0-beta.1 | 139 | 10/6/2021 |
1.0.0-alpha.2 | 177 | 10/6/2021 |
1.0.0-alpha.1 | 187 | 10/5/2021 |
- BREAKING CHANGE: this update upgrades the MongoDb driver to v3.1 which contains breaking changes including the removal of the IMongoQueryable interface. It is replaced with the IQueryable interface