Papst.EventStore.MongoDB
7.2.7
dotnet add package Papst.EventStore.MongoDB --version 7.2.7
NuGet\Install-Package Papst.EventStore.MongoDB -Version 7.2.7
<PackageReference Include="Papst.EventStore.MongoDB" Version="7.2.7" />
<PackageVersion Include="Papst.EventStore.MongoDB" Version="7.2.7" />
<PackageReference Include="Papst.EventStore.MongoDB" />
paket add Papst.EventStore.MongoDB --version 7.2.7
#r "nuget: Papst.EventStore.MongoDB, 7.2.7"
#:package Papst.EventStore.MongoDB@7.2.7
#addin nuget:?package=Papst.EventStore.MongoDB&version=7.2.7
#tool nuget:?package=Papst.EventStore.MongoDB&version=7.2.7
Papst.EventStore.MongoDB
MongoDB based EventStore Implementation.
Usage
High-Level Event Store (IEventStore)
services.AddMongoDBEventStore(options => {
options.ConnectionString = "mongodb://localhost:27017";
options.DatabaseName = "EventStore";
});
var eventStore = serviceProvider.GetRequiredService<IEventStore>();
Low-Level Event Store (ILowLevelEventStore)
For handling events as raw JSON objects without type information:
var lowLevelEventStore = serviceProvider.GetRequiredService<ILowLevelEventStore>();
var streamId = Guid.NewGuid();
var stream = await lowLevelEventStore.CreateAsync(streamId, "MyAggregate");
// Append a low-level event (as JObject)
var evt = JObject.Parse(@"{ ""eventData"": ""value"" }");
await stream.AppendAsync(Guid.NewGuid(), "MyEvent", evt);
Deleting an Event Stream
DeleteAsync removes the stream from both collections — all event documents from the EventStreams collection and the corresponding entry from the StreamMetadata collection:
await eventStore.DeleteAsync(streamId);
On a replica set the two deletes are executed inside a MongoDB transaction to keep them atomic; on a standalone instance (no transaction support) it falls back to sequential deletes, mirroring the batch append behaviour. If the stream does not exist, an EventStreamNotFoundException is thrown. The action is logged at Information level.
Features
- Full IEventStore, ILowLevelEventStore and IEventStream interface implementation
- Full ILowLevelEventStream interface implementation for low-level event handling
- MongoDB native async operations
- Transaction support for batch operations (with automatic fallback for standalone instances)
- Efficient querying with MongoDB indexes
- Snapshot support
- Comprehensive logging using LoggerMessage source generator
Architecture
Separate Metadata Collection
The MongoDB implementation uses two collections to store event stream data:
- EventStreams Collection - Stores individual event documents (events and snapshots)
- StreamMetadata Collection - Stores metadata for each stream
Why Separate Collections?
Performance Benefits:
- Faster Stream Queries: The metadata collection stores a small document per stream (StreamId, Version, Created, TargetType, etc.), enabling instant retrieval of stream information without scanning through potentially thousands of events.
- Optimized Version Tracking: Updating the current version of a stream requires only updating a single small document in the metadata collection, rather than querying all events to determine the latest version.
- Efficient Index Usage: The metadata collection has a unique index on StreamId, ensuring O(1) lookups for stream existence checks and metadata retrieval.
Data Integrity:
- Atomic Stream Creation: The unique index on StreamId in the metadata collection provides database-level enforcement of stream uniqueness, preventing race conditions during concurrent stream creation.
- Version Consistency: Storing the current version in metadata ensures consistent version tracking even when events are being appended concurrently.
Scalability:
- Separation of Concerns: As streams grow to contain thousands or millions of events, the metadata collection remains small and performant.
- Query Optimization: Queries that only need stream metadata (e.g., checking if a stream exists, getting the current version) don't need to access the events collection at all.
This design pattern is common in event sourcing implementations and provides significant performance benefits as the event store scales.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net11.0 is compatible. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
- MongoDB.Driver (>= 3.11.0 && < 4.0.0)
- Newtonsoft.Json (>= 13.0.4)
- Papst.EventStore (>= 7.2.0 && < 8.0.0)
- SharpCompress (>= 0.48.1)
-
net11.0
- MongoDB.Driver (>= 3.11.0 && < 4.0.0)
- Newtonsoft.Json (>= 13.0.4)
- Papst.EventStore (>= 7.2.0 && < 8.0.0)
- SharpCompress (>= 0.48.1)
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 |
|---|---|---|
| 7.2.7 | 45 | 11/24/2026 |
| 7.1.4 | 48 | 11/24/2026 |
| 7.0.14 | 80 | 11/23/2026 |
| 7.0.12 | 142 | 9/19/2026 |
| 7.0.4 | 128 | 8/18/2026 |
| 6.4.5 | 133 | 8/10/2026 |
| 6.3.3 | 133 | 8/2/2026 |
| 6.2.2 | 129 | 7/19/2026 |
| 6.1.2 | 130 | 5/16/2026 |
| 6.0.14 | 129 | 5/6/2026 |
| 6.0.11 | 124 | 5/2/2026 |
| 6.0.9 | 150 | 4/12/2026 |
| 6.0.4 | 143 | 4/11/2026 |
| 6.0.3 | 138 | 4/11/2026 |
| 5.4.9 | 144 | 2/13/2026 |