Add MongoDB storage implementation for EventStore#255
Conversation
Co-authored-by: MPapst <16494676+MPapst@users.noreply.github.com>
Co-authored-by: MPapst <16494676+MPapst@users.noreply.github.com>
| /// <summary> | ||
| /// Custom BSON serializer for Newtonsoft.Json JObject | ||
| /// </summary> | ||
| internal class JObjectSerializer : SerializerBase<JObject> |
There was a problem hiding this comment.
Rename to JObjectBsonSerializer
There was a problem hiding this comment.
Renamed to JObjectBsonSerializer in commit 7ce073a.
| { | ||
| if (_indexesCreated) return; | ||
|
|
||
| // Index on StreamId and Version for efficient querying |
There was a problem hiding this comment.
Add an Index on the Name of the Event for future use.
There was a problem hiding this comment.
Added index on the Name field for future event name queries in commit 7ce073a. The index is created in the EnsureIndexesAsync method.
| /// <summary> | ||
| /// Configuration options for MongoDB EventStore | ||
| /// </summary> | ||
| public class MongoDBEventStoreOptions |
There was a problem hiding this comment.
Replace Default values by string.Empty.
Add a Validation using PostConfigure for the Values.
There was a problem hiding this comment.
Replaced default values with string.Empty and added PostConfigure validation in commit 7ce073a. The validation ensures ConnectionString and DatabaseName are provided, and sets default values for collection names if not specified.
…ng, add validation, document metadata collection separation Co-authored-by: MPapst <16494676+MPapst@users.noreply.github.com>
Added comprehensive logging using LoggerMessage Code Generator in commit 7ce073a. Logging includes:
Updated README with detailed explanation of why metadata is stored in a separate collection, covering performance benefits (faster queries, optimized version tracking), data integrity (atomic stream creation, version consistency), and scalability advantages. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot please explain why a second collection is used for metadata instead of having all entities in one collection. |
The two-collection design separates EventStreams (individual events/snapshots) from StreamMetadata (stream-level information) for several key reasons: Performance Benefits:
Data Integrity:
Scalability:
Alternative (Single Collection):
This pattern is common in event sourcing (similar to having separate "streams" and "events" tables in SQL). |
Implements MongoDB storage provider for the EventStore library with full
IEventStoreandIEventStreaminterface support.Implementation
JObjectBsonSerializerfor BSON compatibility withJObjectandGuid(serialized as strings)Usage
Architecture
Two-Collection Design
The implementation uses separate collections for events and metadata:
This separation provides:
Technical Notes
MongoDBEventStoreimplementsIDisposableforSemaphoreSlimcleanupNotSupportedExceptionfor standalone MongoDB with automatic fallback and loggingBsonSerializeron first instantiationOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.