MongoZen 0.10.6
See the version list below for details.
dotnet add package MongoZen --version 0.10.6
NuGet\Install-Package MongoZen -Version 0.10.6
<PackageReference Include="MongoZen" Version="0.10.6" />
<PackageVersion Include="MongoZen" Version="0.10.6" />
<PackageReference Include="MongoZen" />
paket add MongoZen --version 0.10.6
#r "nuget: MongoZen, 0.10.6"
#:package MongoZen@0.10.6
#addin nuget:?package=MongoZen&version=0.10.6
#tool nuget:?package=MongoZen&version=0.10.6
MongoZen
MongoDB is nice and all, but the driver experience in C# usually sucks. You either end up with reflection-heavy "automagical" repositories, or you're writing manual BsonDocument boilerplate for aggregation pipelines like it's 2011.
Now, the idea behind MongoZen is to take a Mongo driver then add "Unit of Work" and "Identity Map" patterns from EF Core or RavenDB. But I wanted them to actually be fast and as MongoDB-native as possible.
So, why should you care?
- No Reflection on the Hot Path: Instead, there are Roslyn Source Generators to wire up your
DbSetand sessions at compile-time. If it's slow, it's not because of us. - Identity Map: If you load the same document twice in one session, you get the same instance.
- Automatic Change Tracking: Modify POCOs directly. When you call
SaveChangesAsync(), we figure out what changed and flush it in a single bulk write operation per collection. Or a transaction if supported. - RavenDB-inspired API:
Store,Delete,LoadAsync. It's a clean API that doesn't get in your way. - In-Memory Provider: Write tests that run fast without spinning up a Docker "testcontainer" container every time.
Quick Start
1. Define your Context
You need a partial class so the generator can do its thing.
public partial class MyDbContext : MongoZen.DbContext
{
// These properties are automatically initialized
public IDbSet<Person> People { get; set; } = null!;
public MyDbContext(DbContextOptions options) : base(options) { }
}
2. Use it
Everything happens inside a session.
var options = DbContextOptions.CreateForMongo("mongodb://localhost:27017", "MyDatabase");
var db = new MyDbContext(options);
await using var session = db.StartSession();
// Fetch Alice
var alice = await session.LoadAsync<Person>("alice-id");
// Just change the property. No .Update() needed.
alice.Age = 31;
// Load someone else while we're at it
var bob = new Person { Name = "Bob", Age = 25 };
session.Store(bob);
// One network round-trip to commit everything
await session.SaveChangesAsync();
Testing
Just swap the options. It's that simple.
var options = new DbContextOptions(); // Default is In-Memory
var testDb = new MyDbContext(options);
More Info
Check out our Wiki for:
License
MIT. Go build something cool.
| Product | Versions 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 is compatible. 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. |
-
net10.0
- MongoDB.Driver (>= 3.3.0)
- SharpArena (>= 0.7.20)
-
net8.0
- MongoDB.Driver (>= 3.3.0)
- SharpArena (>= 0.7.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Changes since version v2.0.1.0
:sparkles: New Features:
- [`0e85a6c`](https://github.com/myarichuk/Library.Template/commit/0e85a6c62eee9c66c38785e062ce8337169c982e) - automatically fill release notes when generating nuspec *(commit by [@myarichuk](https://github.com/myarichuk))*