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
                    
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="Papst.EventStore.MongoDB" Version="7.2.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Papst.EventStore.MongoDB" Version="7.2.7" />
                    
Directory.Packages.props
<PackageReference Include="Papst.EventStore.MongoDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Papst.EventStore.MongoDB --version 7.2.7
                    
#r "nuget: Papst.EventStore.MongoDB, 7.2.7"
                    
#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.
#:package Papst.EventStore.MongoDB@7.2.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Papst.EventStore.MongoDB&version=7.2.7
                    
Install as a Cake Addin
#tool nuget:?package=Papst.EventStore.MongoDB&version=7.2.7
                    
Install as a Cake Tool

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:

  1. EventStreams Collection - Stores individual event documents (events and snapshots)
  2. 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 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. 
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
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